<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[When Engineers meet AI: 🚀 Software Engineering]]></title><description><![CDATA[Exploring the programming languages like Rust, compilers concepts, and Broader tech & dev practices (infra, tools, setups, developer experience)]]></description><link>https://engineersmeetai.substack.com/s/software-engineering</link><image><url>https://substackcdn.com/image/fetch/$s_!8VIu!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b95dd4-426e-484e-b2ff-37a5cf793557_103x103.png</url><title>When Engineers meet AI: 🚀 Software Engineering</title><link>https://engineersmeetai.substack.com/s/software-engineering</link></image><generator>Substack</generator><lastBuildDate>Sat, 02 May 2026 12:50:27 GMT</lastBuildDate><atom:link href="https://engineersmeetai.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Kannan Kalidasan]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[engineersmeetai@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[engineersmeetai@substack.com]]></itunes:email><itunes:name><![CDATA[Kannan Kalidasan]]></itunes:name></itunes:owner><itunes:author><![CDATA[Kannan Kalidasan]]></itunes:author><googleplay:owner><![CDATA[engineersmeetai@substack.com]]></googleplay:owner><googleplay:email><![CDATA[engineersmeetai@substack.com]]></googleplay:email><googleplay:author><![CDATA[Kannan Kalidasan]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Why Distributed Systems Prefer Leases Over Locks]]></title><description><![CDATA[The Time-Bound Key: Understanding Leases in Distributed Systems]]></description><link>https://engineersmeetai.substack.com/p/why-distributed-systems-prefer-leases</link><guid isPermaLink="false">https://engineersmeetai.substack.com/p/why-distributed-systems-prefer-leases</guid><dc:creator><![CDATA[Kannan Kalidasan]]></dc:creator><pubDate>Tue, 06 Jan 2026 21:46:09 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!DZiu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Problem with the Forever Lock &#128273;</h2><p><strong>To understand a lease, we must first understand the problem it solves.</strong> </p><p>Imagine a <strong>distributed lock</strong> as a simple, physical padlock on a shared resource, like a critical database table or a configuration file. When a server, or client, wants to use the resource, it acquires the lock, uses the resource, and then explicitly releases the lock. This ensures mutual exclusion: only one client can access the resource at a time.</p><pre><code>Acquire &#8594; Hold &#8594; Release</code></pre><p>In a perfect world, this works flawlessly. But distributed systems are inherently imperfect. They suffer from <em><strong>network latency, machine crashes, and unpredictable delays.</strong></em></p><p><em><strong>Consider the following scenario:</strong></em></p><ol><li><p><strong>Client A</strong> successfully acquires the lock &#128273;.</p></li><li><p><strong>Client A</strong> begins working on the shared resource &#128679;.</p></li><li><p>Before <strong>Client A</strong> can release the lock, one of two things happens:</p><ol><li><p><strong>Client A crashes</strong> &#128561; (a sudden power failure, for example).</p></li><li><p>Client A experiences a <strong>network partition &#128732; </strong> (it gets temporarily cut off from the rest of the network).</p></li></ol></li></ol><p>In both cases, <strong>Client A is gone or unreachable</strong>, and the lock is never explicitly released. The resource is now deadlocked. No other client can ever access it, and the entire system grinds to a halt. The lock, intended to protect the resource, has become its prison.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2AAK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2AAK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!2AAK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!2AAK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!2AAK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2AAK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png" width="406" height="270.75961538461536" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:406,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Illustration of a simple lock problem where the key holder disappears.&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Illustration of a simple lock problem where the key holder disappears." title="Illustration of a simple lock problem where the key holder disappears." srcset="https://substackcdn.com/image/fetch/$s_!2AAK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!2AAK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!2AAK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!2AAK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369f372-2f48-465e-8a62-e57f7d00badd_1536x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The client holding the key has disappeared, leaving the door locked forever. </p><p><em><strong>This is the critical vulnerability of a simple, non-expiring lock in an unreliable environment.</strong></em></p><div><hr></div><h2>&#128273; Leases : A Lock with an Expiration Date &#9201;&#65039;</h2><p>A <strong>lease</strong> is essentially a <strong>time-bound</strong> grant of authority over a resource. Think of it not as owning a key forever, but as renting a resource for a fixed period.</p><div class="pullquote"><p>A <strong>lease</strong> is a contract between a <strong>Lease Grantor</strong> (the central authority) and a <strong>Client</strong> (the server requesting access) that grants the Client exclusive rights to a resource for a specific duration, known as the <strong>Time-To-Live</strong> (TTL).</p></div><p>The fundamental difference between a lock and a lease is the automatic expiration.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QezU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QezU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png 424w, https://substackcdn.com/image/fetch/$s_!QezU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png 848w, https://substackcdn.com/image/fetch/$s_!QezU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png 1272w, https://substackcdn.com/image/fetch/$s_!QezU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QezU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png" width="720" height="228.6053412462908" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2076bb20-ee11-4045-8609-bb51ef709767_674x214.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:214,&quot;width&quot;:674,&quot;resizeWidth&quot;:720,&quot;bytes&quot;:32523,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/183718476?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QezU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png 424w, https://substackcdn.com/image/fetch/$s_!QezU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png 848w, https://substackcdn.com/image/fetch/$s_!QezU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png 1272w, https://substackcdn.com/image/fetch/$s_!QezU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2076bb20-ee11-4045-8609-bb51ef709767_674x214.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>The Lease Mechanism</h3><blockquote><p>When a client requests a lease, the Lease Grantor issues it with a TTL, say 60 seconds. The client now has exclusive access to the resource for that 60 seconds.</p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DZiu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DZiu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!DZiu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!DZiu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!DZiu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DZiu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png" width="508" height="338.782967032967" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:508,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Illustration of a lease concept with a timer attached to a key.&quot;,&quot;title&quot;:&quot;Illustration of a lease concept with a timer attached to a key.&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Illustration of a lease concept with a timer attached to a key." title="Illustration of a lease concept with a timer attached to a key." srcset="https://substackcdn.com/image/fetch/$s_!DZiu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!DZiu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!DZiu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!DZiu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ef0694-0d03-4973-978a-12ebe401ab9e_1536x1024.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ol><li><p><strong>Acquire:</strong> Client A requests and receives a <strong>lease for 60 seconds.</strong></p></li><li><p><strong>Use:</strong> Client A uses the resource, knowing it has <strong>60 seconds of guaranteed access.</strong></p></li><li><p><strong>Renew:</strong> If Client A needs more time, it must <strong>send a renewal request</strong> to the Grantor before the 60 seconds are up. The Grantor resets the timer.</p></li><li><p><strong>Expire:</strong> If Client A crashes or is partitioned, it cannot renew the lease. After 60 seconds, the <strong>lease automatically expires</strong>, and the Grantor is free to issue a new lease to another client.</p></li></ol><h2>Where Leases Are Used </h2><p>Leases are a fundamental building block in modern, highly available distributed systems. They are the core mechanism that allows systems to recover gracefully from failure.</p><h3>1. Leader Election</h3><p>In many distributed systems (like those using protocols such as <strong>Raft or Paxos, or systems like Kubernetes and etcd</strong>), one server must be designated as the Leader to coordinate all activity.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WbRG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WbRG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!WbRG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!WbRG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!WbRG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WbRG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1676972,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/183718476?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WbRG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!WbRG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!WbRG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!WbRG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84390731-c5cf-4499-bd4a-65c525673ec9_1536x1024.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Mechanism:</strong> Servers compete to acquire a lease on a specific &#8220;leader&#8221; resource. The server that successfully holds the lease is the current leader.</p><p><strong>Fault Tolerance:</strong> If the leader fails, its lease expires. The other servers (followers) detect the expiration and immediately start a new election process to acquire the now-free lease, ensuring the system quickly gets a new leader.</p><h3>2. Cache Consistency</h3><p>When a client caches data locally to improve performance, the central data store needs a way to ensure that cached data doesn&#8217;t become stale.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!64uG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!64uG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!64uG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!64uG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!64uG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!64uG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2864232,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/183718476?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!64uG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!64uG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!64uG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!64uG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf55a084-2236-4cfc-b0a1-f072f600e8cc_1536x1024.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Mechanism:</strong> The central store grants a client a cache lease on a piece of data. While the lease is active, the central store promises not to allow any other client to modify that data. This allows the client to use its local copy with high confidence.</p><p><strong>Performance:</strong> The client avoids constantly checking with the central store, leading to massive performance gains. If the central store needs to update the data, it can try to revoke the lease, or simply wait for it to expire.</p><h3>3. Distributed Coordination</h3><p>Leases are used to coordinate access to any shared resource, ensuring that even if a client fails mid-operation, the resource is eventually released.</p><p>The diagram below shows how a <strong>Lease Grantor (Resource Manager)</strong> manages the flow of authority between server nodes:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!la0x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!la0x!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png 424w, https://substackcdn.com/image/fetch/$s_!la0x!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png 848w, https://substackcdn.com/image/fetch/$s_!la0x!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png 1272w, https://substackcdn.com/image/fetch/$s_!la0x!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!la0x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png" width="656" height="298.1041666666667" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:698,&quot;width&quot;:1536,&quot;resizeWidth&quot;:656,&quot;bytes&quot;:497456,&quot;alt&quot;:&quot;Conceptual diagram of a distributed system lease mechanism.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Conceptual diagram of a distributed system lease mechanism." title="Conceptual diagram of a distributed system lease mechanism." srcset="https://substackcdn.com/image/fetch/$s_!la0x!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png 424w, https://substackcdn.com/image/fetch/$s_!la0x!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png 848w, https://substackcdn.com/image/fetch/$s_!la0x!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png 1272w, https://substackcdn.com/image/fetch/$s_!la0x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7952ae8a-15b0-48cc-876c-c9863642950e_1536x698.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The Grantor ensures that when a lease expires on one node, the authority can be safely passed to the next waiting node, maintaining system continuity.</p><h2>Advantages</h2><p>The adoption of leases over simple locks provides two critical advantages that are essential for building robust systems:</p><h4>1. Superior Fault Tolerance</h4><p>This is the primary benefit. By making the default state of a resource unlocked after a timeout, leases solve the deadlock problem. The system&#8217;s recovery from failure is no longer dependent on a potentially crashed or partitioned client sending a &#8220;release&#8221; message. </p><h4>2. Improved Performance and Reduced Communication</h4><p>Leases allow a client to operate with a high degree of certainty for the duration of the lease. This reduces the need for constant, expensive communication with the central authority.</p><p><strong>For example,</strong> a client with a 60-second lease on a resource knows it has 60 seconds of exclusive access. It can perform multiple operations locally without having to check back with the central lock manager for every single step. This batching of operations significantly reduces network overhead and latency, leading to a much faster and more efficient system overall.</p><h2>Common Mistakes with Leases</h2><h4>1. Lease Too Long &#8594; Slow failover</h4><p>When a node crashes, others must wait for the lease to expire before taking over.<br>Long leases delay recovery and keep the system unavailable longer than necessary.</p><h4>2. Lease Too Short &#8594; Frequent leadership churn</h4><p>Short leases require very frequent renewals to stay valid.<br>Small delays or GC pauses can cause leadership to change unnecessarily.</p><h4>3. No Renewal Buffer &#8594; Accidental lease loss due to clock skew</h4><p>If renewal happens too close to expiry, time drift or network latency can cause failure. The node may lose its lease even though it is still healthy.</p><h4>&#128161; How to Overcome These Issues (A Safe Pattern) </h4><p><em>Renew the lease <strong>well before it expires</strong>, instead of waiting until the last moment.<br>A common and safe practice is to renew at <strong>50&#8211;70% of the TTL</strong>, leaving enough buffer for delays, clock skew, or brief pauses.</em></p><p></p>]]></content:encoded></item><item><title><![CDATA[How to Completely Remove a .env File from Git]]></title><description><![CDATA[Why Deleting Isn&#8217;t Enough]]></description><link>https://engineersmeetai.substack.com/p/how-to-completely-remove-a-env-file</link><guid isPermaLink="false">https://engineersmeetai.substack.com/p/how-to-completely-remove-a-env-file</guid><dc:creator><![CDATA[Kannan Kalidasan]]></dc:creator><pubDate>Mon, 05 Jan 2026 19:23:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!q62R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote><p>Accidentally committing a <code>.env</code> file is a common Git mistake, and it often happens before proper guardrails are fully established. </p><p>Fixing it properly requires understanding <strong>how Git tracks files</strong> and <strong>why deleting a file is not the same as deleting its history</strong>.</p></blockquote><p>This post walks through the correct steps to completely remove a <code>.env</code> file from Git and prevent it from being committed again.</p><pre><code>rm .env
git commit -m "remove env"

//or

echo ".env" &gt;&gt; .gitignore</code></pre><p>This <strong>does not remove the secret</strong>. Because Git doesn&#8217;t track files the way your file system does.</p><h3>How Git actually works</h3><div class="pullquote"><p>Git tracks <strong>snapshots</strong>, not files.</p></div><p>Each commit is a full picture of the repository at that moment.</p><h3>Git has three layers:</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!q62R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!q62R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png 424w, https://substackcdn.com/image/fetch/$s_!q62R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png 848w, https://substackcdn.com/image/fetch/$s_!q62R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png 1272w, https://substackcdn.com/image/fetch/$s_!q62R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!q62R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png" width="482" height="324" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:324,&quot;width&quot;:482,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:64986,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/183455436?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!q62R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png 424w, https://substackcdn.com/image/fetch/$s_!q62R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png 848w, https://substackcdn.com/image/fetch/$s_!q62R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png 1272w, https://substackcdn.com/image/fetch/$s_!q62R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65e847d0-7457-4fad-a117-72ee0b19204a_482x324.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Once a file enters <strong>Commit History</strong>, it stays there forever, unless history is rewritten.</p><p><code>.gitignore</code> only affects <strong>untracked files</strong>.</p><p>If <code>.env</code> was ever committed:</p><ul><li><p>Git already knows about it</p></li><li><p><code>.gitignore</code> will be ignored for that file</p></li></ul><p>That&#8217;s why we must explicitly <strong>remove it from tracking</strong>.</p><h4>Step 0: Assume the secrets are compromised [ Important ]</h4><p>Before touching Git, <strong>rotate any keys, tokens, or passwords</strong> that were in the <code>.env</code> file. Even if you delete the file later, anyone who saw the repo earlier may still have access.</p><h4>Step 1: Add <code>.env</code> to <code>.gitignore</code> (prevents re-commit)</h4><pre><code><code>echo ".env" &gt;&gt; .gitignore
git add .gitignore
git commit -m "Ignore .env"
git push

// or create ~/.gitignore in home directory and make it global
git config --global core.excludesfile ~/.gitignore
</code></code></pre><blockquote><p><code>.gitignore</code> prevents <strong>new</strong> tracking. If <code>.env</code> was already committed, Git will still track it until you untrack it (next step).</p></blockquote><h4>Step 2: Stop tracking <code>.env</code> in the current state</h4><p>If <code>.env</code> is already tracked, remove it from Git (without deleting it locally):</p><pre><code>// Remove .env from Git tracking, but don&#8217;t delete the local file.&#8221;
git rm --cached .env


//Now commit and push:
git commit -m "Stop tracking .env"
git push</code></pre><p>From this point forward:</p><ul><li><p><code>.env</code> is no longer tracked</p></li><li><p><code>.gitignore</code> works correctly</p></li><li><p>future commits are safe</p></li></ul><p>&#9888;&#65039; <strong>But the secret still exists in older commits</strong></p><h4>Step 3: Remove <code>.env</code> from the entire Git history</h4><p>This is the step that actually removes the trace.</p><p>Install <code>git-filter-repo</code></p><pre><code>brew install git-filter-repo     # macOS
# or
pip install git-filter-repo

git filter-repo --path .env --invert-paths </code></pre><blockquote><p>This rewrites all commits and removes <code>.env</code> everywhere. basically it would look like below and Commit hashes change because the history is rebuilt.</p></blockquote><pre><code>Before:
A &#9472;&#9472; B &#9472;&#9472; C &#9472;&#9472; D   (contains .env somewhere)

After:
A'&#9472;&#9472; B'&#9472;&#9472; C'&#9472;&#9472; D'  (no .env anywhere)</code></pre><h4>Step 4: Force-push the cleaned history to remote</h4><p>Now publish the cleaned history to the remote repository:</p><pre><code><code>git push --force --all
git push --force --tags</code></code></pre><p>This replaces the remote history with your cleaned history.</p><h4>Step 5: Verify <code>.env</code> is gone from history</h4><pre><code>// This should return nothing
git log --all -- .env<code> </code></code></pre><h3>Important to remember</h3><ul><li><p>&#9888;&#65039;  Force-pushing rewritten history <strong>breaks existing clones</strong>. So, before running the final cleanup steps:</p><ul><li><p>Inform your team that history will be rewritten</p></li><li><p>Ask them to <strong>pause merges and pushes</strong></p></li><li><p>Make sure no active work depends on the old commit history</p></li><li><p>This avoids broken branches and accidental re-introductions of the file.</p></li></ul></li><li><p>&#9888;&#65039; Don&#8217;t assume GitHub &#8220;purges&#8221; secrets automatically. You should rotate secrets regardless because PR diffs/forks/caches may still expose content.</p></li></ul><ul><li><p>Team members or contributors should re-clone, or hard reset</p></li></ul><pre><code><code>git fetch --all
git reset --hard origin/main</code></code></pre><ul><li><p>&#9888;&#65039; GitHub <strong>cannot delete history from forks you don&#8217;t control</strong>.</p></li></ul><p>If someone forked the repo <strong>before</strong> cleanup:</p><ul><li><p>Their fork still contains the old history</p></li><li><p>GitHub support cannot remove that</p></li></ul><p>This is another reason secret rotation matters more than cache clearing.</p><div class="pullquote"><p><strong>Rotating secrets is the only reliable fix.</strong></p></div><p></p>]]></content:encoded></item><item><title><![CDATA[A Practical Guide to AI Dotfiles]]></title><description><![CDATA[How developers and AI agent builders can keep their environments perfectly in sync]]></description><link>https://engineersmeetai.substack.com/p/a-practical-guide-to-ai-dotfiles</link><guid isPermaLink="false">https://engineersmeetai.substack.com/p/a-practical-guide-to-ai-dotfiles</guid><dc:creator><![CDATA[Kannan Kalidasan]]></dc:creator><pubDate>Sat, 25 Oct 2025 22:36:47 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/8ee3bc7d-09b8-4d8c-b2c1-ac79a8f3e1f4_472x245.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote><p><strong>Tag</strong>: Engineer&#8217;s Toolbox<br>&#9203;  <strong>10 min focus read</strong>, best read on <strong>Desktop </strong>includes code and screenshots</p></blockquote><p><em>Hello Everyone &#128075; I&#8217;m considering <a href="https://engineersmeetai.substack.com/p/20-years-in-tech-taught-me-this-should">adding more practical, deep-dive software engineering and data related tech stack explorations alongside the usual AI posts</a>. Would you be up for that?  Thanks to everyone who took a moment to fill out my recent survey, your responses mean a lot.</em> </p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://engineersmeetai.substack.com/survey/4778306?token=&quot;,&quot;text&quot;:&quot;Start Survey&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://engineersmeetai.substack.com/survey/4778306?token="><span>Start Survey</span></a></p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MIbB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MIbB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png 424w, https://substackcdn.com/image/fetch/$s_!MIbB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png 848w, https://substackcdn.com/image/fetch/$s_!MIbB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png 1272w, https://substackcdn.com/image/fetch/$s_!MIbB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MIbB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png" width="775" height="410" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/df1e7c4b-077c-472e-859e-c68866a547aa_775x410.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:410,&quot;width&quot;:775,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:710346,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176570715?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MIbB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png 424w, https://substackcdn.com/image/fetch/$s_!MIbB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png 848w, https://substackcdn.com/image/fetch/$s_!MIbB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png 1272w, https://substackcdn.com/image/fetch/$s_!MIbB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf1e7c4b-077c-472e-859e-c68866a547aa_775x410.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>You</strong>&#8217;ve got a new laptop, maybe it&#8217;s your own, or one from a new startup job and the first thing you want is for your terminal or IDE to <em>feel right</em>.<br>Your shell prompt ( <code>.bashrc</code>, <code>.zshrc )</code>, your aliases, your shortcuts, Vim ( <code>.config/nvim</code> ), everything configured perfectly to how you work.</p><ul><li><p>custom color schemes that make logs readable.</p></li><li><p>prompt themes that show your current branch or virtualenv.</p></li><li><p>handy aliases that cut down on repetitive typing.</p></li></ul><p>But fast forward a year.</p><p>You&#8217;ve switched companies, or maybe you just want to mirror your setup across two machines. Suddenly, that finely crafted environment is gone. A blank terminal window stares back no aliases, no colors, no familiar shortcuts.</p><p><em>Painful, right? Let me introduce a small but powerful thing&#8230;.</em></p><h3>What is Dotfiles ?</h3><ul><li><p>A <strong>dotfile</strong> is a configuration file whose name begins with a dot (e.g. <code>.bashrc</code>, <code>.zshrc</code>, <code>.claude</code>, <code>.gitconfig</code>, <code>.tmux.conf</code>). These are called hidden files by default in Unix-style systems.</p></li></ul><ul><li><p>It is like a <strong>developer blueprint</strong>, a version-controlled way to preserve your preferences, configurations, and scripts. They turn the painful setup process into a one-command sync, so you can bring your workspace anywhere.</p></li></ul><ul><li><p>Developers often collect all such customizations into a single Git repository (often named <code>dotfiles</code>) so they can easily back up those configs (history, diffs, rollbacks), sync them across multiple machines and share useful configs (open source your dotfiles).</p></li></ul><h3>&#129302; Dotfiles for Agent Developers</h3><div class="pullquote"><p>Now, as developers start building <strong>AI agents</strong>, there&#8217;s a new dimension to this idea. Traditional dotfiles configure your tools; <strong>AI dotfiles</strong> configure your agents workspace.</p></div><p>Although AI dotfiles are generally stored within project repositories for version control, you can also maintain a personal set in your home directory for private or global agent configurations that don&#8217;t interfere with project-level setups. These personal settings can even be integrated into your IDE, AI-powered terminal, or any other workspace tools you use.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!j_HS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!j_HS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png 424w, https://substackcdn.com/image/fetch/$s_!j_HS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png 848w, https://substackcdn.com/image/fetch/$s_!j_HS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png 1272w, https://substackcdn.com/image/fetch/$s_!j_HS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!j_HS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png" width="1456" height="967" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:967,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:249339,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176570715?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!j_HS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png 424w, https://substackcdn.com/image/fetch/$s_!j_HS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png 848w, https://substackcdn.com/image/fetch/$s_!j_HS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png 1272w, https://substackcdn.com/image/fetch/$s_!j_HS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03fe73eb-0231-4b79-9b41-6f3c99626d3b_1636x1086.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Figure 1: Dot files - folder structure example</figcaption></figure></div><p><em>Example:<strong> .agentrc</strong></em></p><pre><code># ~/.ai-dotfiles/.agentrc
# example
<strong>name</strong>: &#8220;analytics-engineer&#8221;
<strong>role</strong>: &#8220;AI data assistant for local projects&#8221;
<strong>personality</strong>: &#8220;curious, concise, technical&#8221;
<strong>goals:</strong>
  - Assist in analyzing, visualizing, and generate code
  - Maintain consistent style
<strong>capabilities:</strong>
  - visualize_data
  - summarize_data
<strong>startup_message:</strong> &#8220;Analyst ready to assist&#8221;
</code></pre><p><em>Example:<strong> </strong></em><code>.</code><em><strong>aiconfig</strong></em></p><pre><code># ~/.ai-dotfiles/.aiconfig
<strong>model:</strong> &#8220;llama3.1&#8221;
<strong>temperature:</strong> 0.7
<strong>providers:</strong>
  <strong>openai:</strong>
    <strong>api_key:</strong> &#8220;{{ env.OPENAI_API_KEY }}&#8221;
  <strong>ollama:</strong>
    <strong>model_path:</strong> &#8220;/usr/local/share/ollama/models/&#8221;
<strong>memory_backend:</strong> &#8220;local&#8221;
<strong>log_level:</strong> &#8220;info&#8221;</code></pre><p><em>Example: <strong>Role-Based Prompt</strong></em></p><pre><code># ai-dotfiles/prompts/data_analyst.md
# Data Analyst Template

<em><strong>You are a data analyst AI. Your task is to understand, summarize, and visualize datasets provided in CSV, JSON, or tabular formats.</strong></em>

<strong>Focus areas:</strong>
- Key trends and patterns in the data
- Missing values, anomalies, or outliers
- Summary statistics (mean, median, counts, etc.)
- Suggested visualizations (histograms, bar charts, line plots, scatter plots)

<strong>Respond in this format:</strong>
1. <strong>**Summary**</strong>
   - Brief overview of the dataset
   - Key observations
2. <strong>**Insights**</strong>
   - Interesting trends or patterns
   - Any anomalies or noteworthy points
3. <strong>**Suggested Visualizations**</strong>
   - List of charts or plots that help understand the data
   - Include recommended libraries or tools (e.g., matplotlib, seaborn)
4. <strong>**Next Steps**</strong>
   - Recommendations for further analysis or modeling</code></pre><h3>&#129504; Addressing Key Challenges</h3><h4>&#10067; Managing Sensitive Data in AI Dotfiles</h4><p>AI dotfiles may have 2 kinds of files:</p><ol><li><p><strong>Public setup files</strong> : safe to share (prompt templates, skills, workflows)</p></li><li><p><strong>Private secrets</strong> : must <em>never</em> be shared (API keys, memory snapshots, tokens)</p></li></ol><h4>&#9989; Solution</h4><p>To safely version-control your repo, you can use a <code>.gitignore</code> file and ensures your secrets stay local while still keeping your AI dotfiles organized and portable.</p><pre><code># ~/.ai-dotfiles/.gitignore

# Sensitive AI configs
.aiconfig
memory/
*.env</code></pre><h4>&#10067; Config files must stay in the right place</h4><p>Tools like Bash, Git, and nvim look for configs in very specific places like:</p><pre><code>~/.bashrc              # Bash default location
~/.gitconfig           # Git default location
~/.config/nvim         # Nvim default location</code></pre><p>If you move those into subfolders like <code>~/dotfiles/git/.gitconfig</code>, they simply won&#8217;t be loaded anymore. Now, How do we organize the dotfiles in subfolders structures mentioned in <strong>Figure 1.</strong></p><h4>&#9989; Solution : Bare Git repository</h4><p>Normally, when you create a Git repo, Git adds a hidden <code>.git</code> folder inside that directory to track changes. But you don&#8217;t want a <code>.git</code> folder sitting in your home folder, that would look messy. </p><blockquote><p><em>A <strong>bare Git repository</strong> has <strong>no working directory</strong>, only the Git database (commits, branches, etc.). So instead of having </em><code>.git</code><em> inside your home folder, you store it somewhere else (like </em><code>~/.config</code><em>) and tell Git to <strong>treat your home directory as the working tree</strong>.</em></p></blockquote><ul><li><p>All your real config files stay where they are (<code>~/.bashrc</code>, <code>~/.zshrc</code>, etc.)</p></li><li><p>The <code>dotfiles/</code> folder secretly holds your Git history</p></li><li><p>You manage everything using the <code>config</code> command ( you can alias whatever you like )</p></li></ul><h4>&#10067; Managing Subfolder Structures in the Repository</h4><p>You want to organize dotfiles into subfolders (<code>bash/</code>, <code>git/</code>, <code>nvim/, ai-dotfiles/ </code>) for clarity and maintainability, but you still need the tools to load the files correctly.</p><h3>&#9989; Solution : Hybrid Dotfiles Setup</h3><h4>1&#65039;&#8419;  Track live configs locally with a bare repo (<code>.dotfiles</code>)</h4><ul><li><p>Keep your actual dotfiles (<code>~/.bashrc, ~/.gitconfig, .agentrc</code>, etc.) in their normal locations because tools expect them there.</p></li><li><p>Use a <strong>bare Git repository</strong> (<code>~/.dotfiles</code>) to track these files.</p></li><li><p>This allows you to <strong>version-control your live environment</strong>, keep full history, and roll back changes without moving or reorganizing your files.</p></li><li><p>Your secrets remain <strong>local</strong> and are never accidentally pushed.</p></li></ul><h4>2&#65039;&#8419;  Mirror configs to a structured, shareable folder (dotfiles/)</h4><ul><li><p>Create a <strong>copy or symlink structure</strong> in <code>~/dotfiles/</code> for publishing or backup.</p></li><li><p>Organize files into subfolders (e.g., <code>bash/</code>, <code>git/</code>, <code>ai-dotfiles/</code>) so it&#8217;s easy to browse and maintain.</p></li><li><p>Ignore sensitive files (like <code>.aiconfig</code> or <code>memory/</code>) to keep secrets safe.</p></li><li><p>Use a small script (<code>sync_dotfiles.sh</code>) to <strong>automatically mirror changes</strong> from your live environment to the structured repo.</p></li></ul><h4>3&#65039;&#8419; Benefits of this hybrid approach</h4><ul><li><p><code>.dotfiles</code> = <strong>private journal of live configs</strong>, tracks everything locally, including experiments</p></li><li><p><code>dotfiles/</code> = <strong>curated, public-friendly snapshot</strong> ready for GitHub or sharing</p></li><li><p>Keeps your workflow safe, organized, and reproducible on <strong>any machine</strong>, and protecting secrets.</p></li><li><p>Your <strong>dotfiles</strong> make your developer setup reproducible.</p></li><li><p>Your <strong>ai-dotfiles</strong> make your agent setup reproducible.</p></li></ul><div class="poll-embed" data-attrs="{&quot;id&quot;:394323}" data-component-name="PollToDOM"></div><div><hr></div><h3>&#129513; Let&#8217;s Put It Into Practice</h3><p><em>For a clear example and all the scripts mentioned below, please check out my personal dotfiles repository: <a href="https://github.com/kannandreams/dotfiles">https://github.com/kannandreams/dotfiles</a></em></p><h4>1&#65039;&#8419; Push to Repository (Sync Dotfiles)</h4><p><strong>Step 1: Track live files in </strong><code>$HOME</code><strong> using bare repo</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!o705!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!o705!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png 424w, https://substackcdn.com/image/fetch/$s_!o705!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png 848w, https://substackcdn.com/image/fetch/$s_!o705!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png 1272w, https://substackcdn.com/image/fetch/$s_!o705!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!o705!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png" width="1456" height="735" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:735,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:158057,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176570715?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!o705!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png 424w, https://substackcdn.com/image/fetch/$s_!o705!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png 848w, https://substackcdn.com/image/fetch/$s_!o705!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png 1272w, https://substackcdn.com/image/fetch/$s_!o705!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dcbc05-c121-47bb-87d8-921dee99f955_1636x826.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Step 2: Mirror into structured repo (</strong><code>dotfiles/</code><strong>)</strong></p><pre><code># Run sync script to copy live configs into organized folders
~/dotfiles/sync_dotfiles.sh</code></pre><p><strong>Output</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QXJf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QXJf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png 424w, https://substackcdn.com/image/fetch/$s_!QXJf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png 848w, https://substackcdn.com/image/fetch/$s_!QXJf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png 1272w, https://substackcdn.com/image/fetch/$s_!QXJf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QXJf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png" width="830" height="656" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:656,&quot;width&quot;:830,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:138188,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176570715?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QXJf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png 424w, https://substackcdn.com/image/fetch/$s_!QXJf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png 848w, https://substackcdn.com/image/fetch/$s_!QXJf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png 1272w, https://substackcdn.com/image/fetch/$s_!QXJf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F244edf1b-3eac-440d-b53b-d0efbc62ee4d_830x656.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZYxY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZYxY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png 424w, https://substackcdn.com/image/fetch/$s_!ZYxY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png 848w, https://substackcdn.com/image/fetch/$s_!ZYxY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png 1272w, https://substackcdn.com/image/fetch/$s_!ZYxY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZYxY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png" width="946" height="269" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:269,&quot;width&quot;:946,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:44770,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176570715?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZYxY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png 424w, https://substackcdn.com/image/fetch/$s_!ZYxY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png 848w, https://substackcdn.com/image/fetch/$s_!ZYxY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png 1272w, https://substackcdn.com/image/fetch/$s_!ZYxY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82af8b1-0c52-4165-9e86-b18aea044e5c_946x269.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4>2&#65039;&#8419; Setup a New Machine (Bootstrap)</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q9Wb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q9Wb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png 424w, https://substackcdn.com/image/fetch/$s_!Q9Wb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png 848w, https://substackcdn.com/image/fetch/$s_!Q9Wb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png 1272w, https://substackcdn.com/image/fetch/$s_!Q9Wb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q9Wb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png" width="1456" height="635" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:635,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:124742,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176570715?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Q9Wb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png 424w, https://substackcdn.com/image/fetch/$s_!Q9Wb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png 848w, https://substackcdn.com/image/fetch/$s_!Q9Wb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png 1272w, https://substackcdn.com/image/fetch/$s_!Q9Wb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8851bc16-ded0-4926-bbe4-8f4b21f5e8ab_1636x714.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Tools &amp; Inspirations</h2><p>As your dotfiles grow, you may want more structure or tooling. Here are common tools and few popular repos for inspiration</p><ul><li><p><strong><a href="https://www.chezmoi.io/">chezmoi</a></strong> &#8212; allows templating, encryption of secrets, multi-OS support. </p></li><li><p><strong><a href="https://github.com/yadm-dev/yadm">YADM</a></strong> &#8212; &#8220;Yet Another Dotfiles Manager&#8221;</p></li><li><p><a href="https://dotfiles.github.io/utilities/">General-purpose dotfiles utilities</a></p></li><li><p>Tom Payne&#8217;s dotfiles managed with chezmoi <a href="https://github.com/twpayne/dotfiles?utm_source=chatgpt.com">GitHub</a></p></li><li><p>thoughtbot&#8217;s dotfiles (uses <code>rcup</code>, local override pattern) <a href="https://github.com/thoughtbot/dotfiles?utm_source=chatgpt.com">GitHub</a></p></li><li><p>holman&#8217;s dotfiles (topic-based layout, auto symlinking script) <a href="https://github.com/holman/dotfiles?utm_source=chatgpt.com">GitHub</a></p></li></ul><div><hr></div><p><strong>&#129302; </strong><em><strong>AI runs on compute. I run on coffee. Fuel the next post if you enjoyed this one!</strong></em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://buymeacoffee.com/untitledhuman&quot;,&quot;text&quot;:&quot;Buy KK a coffee&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://buymeacoffee.com/untitledhuman"><span>Buy KK a coffee</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Dynamic Dispatch: From Classic OOP to Modern AI]]></title><description><![CDATA[Exploring how Python, ML frameworks, and agent systems leverage runtime method resolution]]></description><link>https://engineersmeetai.substack.com/p/dynamic-dispatch-from-classic-oop</link><guid isPermaLink="false">https://engineersmeetai.substack.com/p/dynamic-dispatch-from-classic-oop</guid><dc:creator><![CDATA[Kannan Kalidasan]]></dc:creator><pubDate>Sat, 18 Oct 2025 19:22:13 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/4295f1ae-6f19-4550-afa8-34a3815803a8_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we talk about AI today, we think of neural networks, transformers, and agents that reason and act. But behind the scenes, the software engineering that makes these systems work often relies on classic object-oriented programming techniques like the <strong>Virtual Method Table (VMT)</strong>, a mechanism for flexible method dispatch and polymorphism.</p><p>From an engineering perspective, it&#8217;s fascinating to see how this concept scales. <strong>VMTs and Python&#8217;s dynamic dispatch</strong> form the backbone of how ML frameworks like PyTorch and TensorFlow route computations, and how AI agents dynamically decide which tools to execute.</p><p><em>Let&#8217;s understand these concepts with practical code examples.</em></p><h2>What is a Virtual Method Table?</h2><p>A <strong>Virtual Method Table (VMT)</strong>, also known as a <strong>virtual function table</strong> or <strong>vtable</strong>, is a mechanism predominantly used in object-oriented programming languages such as C++ to implement <strong>dynamic dispatch</strong> or <strong>runtime polymorphism</strong>.</p><div class="pullquote"><p><em>Its primary purpose is to resolve calls to virtual functions at runtime, rather than at compile time.</em></p></div><p><strong>Key characteristics of VMTs include:</strong></p><ul><li><p><strong>Dynamic Dispatch:</strong> Enables selecting and invoking the appropriate method implementation at runtime based on an <em><strong>object&#8217;s actual type</strong></em> <em><strong>rather than its declared type.</strong></em></p></li><li><p><strong>Polymorphism:</strong> Allows objects from different classes to be treated as instances of a common base class, letting a single interface represent multiple underlying behaviors.</p></li><li><p><strong>Modularity and Extensibility:</strong> Supports modular design by making it easy to introduce new behaviors through derived classes, helping systems evolve without major refactoring.</p></li></ul><p>Lets try to understand with C++ code example.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q223!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q223!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png 424w, https://substackcdn.com/image/fetch/$s_!Q223!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png 848w, https://substackcdn.com/image/fetch/$s_!Q223!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png 1272w, https://substackcdn.com/image/fetch/$s_!Q223!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q223!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png" width="1456" height="983" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:983,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:192377,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176186355?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Q223!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png 424w, https://substackcdn.com/image/fetch/$s_!Q223!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png 848w, https://substackcdn.com/image/fetch/$s_!Q223!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png 1272w, https://substackcdn.com/image/fetch/$s_!Q223!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38a6b21a-bac6-4362-b134-638cfe048812_1556x1050.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4><strong>What&#8217;s Happening &#128083;</strong></h4><ol><li><p><strong>VMT generation:</strong> Both <code>Animal</code> and <code>Dog</code> class have their own VMTs (arrays of pointers to virtual functions).</p></li><li><p><strong>vptr:</strong> Each object stores a hidden pointer (<code>vptr</code>) to its class&#8217;s VMT.</p></li><li><p><strong>Dynamic dispatch:</strong> When <code>a-&gt;speak()</code> is called, the program looks at <code>a</code>&#8217;s vptr to find the correct function in the VMT. Because <code>a</code> points to a <code>Dog</code> object, <code>Dog::speak()</code> is executed, not <code>Animal::speak()</code>.</p><p></p></li></ol><div><hr></div><h2>Python: Dynamic Dispatch Without VTables</h2><div class="pullquote"><p>Python doesn&#8217;t have a fixed <strong>vtable</strong> like C++. Instead, it achieves the same effect dynamically using <strong>dictionaries</strong> and the <strong>class hierarchy</strong>. </p></div><p>Every class in Python has a <code>__dict__</code> , a mapping of method names to function objects. When you call a method, Python looks it up dynamically:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8Sfm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8Sfm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png 424w, https://substackcdn.com/image/fetch/$s_!8Sfm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png 848w, https://substackcdn.com/image/fetch/$s_!8Sfm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png 1272w, https://substackcdn.com/image/fetch/$s_!8Sfm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8Sfm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png" width="1456" height="1013" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1013,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:180455,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176186355?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8Sfm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png 424w, https://substackcdn.com/image/fetch/$s_!8Sfm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png 848w, https://substackcdn.com/image/fetch/$s_!8Sfm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png 1272w, https://substackcdn.com/image/fetch/$s_!8Sfm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34b79a38-1eca-4596-bf68-8fccb0bb5f4b_1616x1124.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>When you run <code>d.speak()</code>, Python:</p><ol><li><p>Checks <code>Dog.__dict__</code> for <code>speak()</code>.</p></li><li><p>If not found, walks up the <strong>Method Resolution Order (MRO)</strong> to <code>Animal</code>.</p><ol><li><p>Disassembling the Method Call (Bytecode Proof)</p></li></ol></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BSwR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BSwR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png 424w, https://substackcdn.com/image/fetch/$s_!BSwR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png 848w, https://substackcdn.com/image/fetch/$s_!BSwR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png 1272w, https://substackcdn.com/image/fetch/$s_!BSwR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BSwR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png" width="865" height="436" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:436,&quot;width&quot;:865,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:71062,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176186355?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!BSwR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png 424w, https://substackcdn.com/image/fetch/$s_!BSwR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png 848w, https://substackcdn.com/image/fetch/$s_!BSwR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png 1272w, https://substackcdn.com/image/fetch/$s_!BSwR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f2e8443-6df1-4c39-adb5-f974104ba71d_865x436.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This lookup chain <em>is <strong>Python&#8217;s virtual dispatch mechanism</strong></em>. It&#8217;s slower than a C++ vtable but infinitely more flexible, you can even <em>replace</em> methods at runtime (a.k.a. monkey patching).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xFZv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xFZv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png 424w, https://substackcdn.com/image/fetch/$s_!xFZv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png 848w, https://substackcdn.com/image/fetch/$s_!xFZv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png 1272w, https://substackcdn.com/image/fetch/$s_!xFZv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xFZv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png" width="1456" height="332" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f958a447-79d3-462b-8045-c4ab517d9245_1502x342.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:332,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43166,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176186355?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xFZv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png 424w, https://substackcdn.com/image/fetch/$s_!xFZv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png 848w, https://substackcdn.com/image/fetch/$s_!xFZv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png 1272w, https://substackcdn.com/image/fetch/$s_!xFZv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff958a447-79d3-462b-8045-c4ab517d9245_1502x342.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div><hr></div><h2>How ML Frameworks use Virtual Dispatch</h2><p>If you thought <strong>VMTs</strong> and <strong>dynamic method lookup</strong> were just for C++ or Python classes, No, Modern <strong>ML frameworks</strong> like <strong>PyTorch</strong> and <strong>TensorFlow</strong> rely on the same core principle of <em>virtual dispatch</em>, they just use it at a much larger, dynamic scale.</p><p>For example, in <strong>PyTorch</strong> we have:</p><ul><li><p><strong>Models as classes</strong> = usually subclassing <code>nn.Module</code> (PyTorch) </p></li><li><p><strong>Forward methods</strong> = Each models define computation</p></li><li><p><strong>Dynamic dispatch</strong> = ensures the right <strong>forward</strong> method is called, without the training loop caring about the specific model.</p><p></p></li></ul><p><strong>Base Class</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-exc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-exc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png 424w, https://substackcdn.com/image/fetch/$s_!-exc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png 848w, https://substackcdn.com/image/fetch/$s_!-exc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png 1272w, https://substackcdn.com/image/fetch/$s_!-exc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-exc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png" width="1456" height="692" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:692,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:133361,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176186355?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-exc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png 424w, https://substackcdn.com/image/fetch/$s_!-exc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png 848w, https://substackcdn.com/image/fetch/$s_!-exc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png 1272w, https://substackcdn.com/image/fetch/$s_!-exc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9382c1-efde-4d3f-8209-bdf39cbc6005_1502x714.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Subclass (Specific Model)</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fjRX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fjRX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png 424w, https://substackcdn.com/image/fetch/$s_!fjRX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png 848w, https://substackcdn.com/image/fetch/$s_!fjRX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png 1272w, https://substackcdn.com/image/fetch/$s_!fjRX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fjRX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png" width="1456" height="512" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:512,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:101515,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176186355?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fjRX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png 424w, https://substackcdn.com/image/fetch/$s_!fjRX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png 848w, https://substackcdn.com/image/fetch/$s_!fjRX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png 1272w, https://substackcdn.com/image/fetch/$s_!fjRX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d41d7ac-1067-48b6-b506-faf11e92f457_1502x528.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Training Loop (Using Polymorphism)</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LyKL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LyKL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png 424w, https://substackcdn.com/image/fetch/$s_!LyKL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png 848w, https://substackcdn.com/image/fetch/$s_!LyKL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png 1272w, https://substackcdn.com/image/fetch/$s_!LyKL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LyKL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png" width="1456" height="981" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:981,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:181821,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176186355?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LyKL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png 424w, https://substackcdn.com/image/fetch/$s_!LyKL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png 848w, https://substackcdn.com/image/fetch/$s_!LyKL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png 1272w, https://substackcdn.com/image/fetch/$s_!LyKL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F047d1864-334d-4993-a8ad-742ac8f327bf_1502x1012.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4><strong>What&#8217;s Happening &#128083;</strong></h4><ol><li><p><strong>Model object</strong> (<code>MyModel</code>) contains a reference to its class.</p></li><li><p><strong>Call to </strong><code>model(x)</code> triggers Python&#8217;s <code>__call__</code> on <code>nn.Module</code>, which internally calls <code>self.forward(x)</code>.</p></li><li><p><strong>Dynamic dispatch</strong> looks in <code>MyModel.__dict__</code> for <code>forward()</code>. If it weren&#8217;t found, it would walk the MRO up to <code>BaseModel</code>.</p></li><li><p><strong>Training loop doesn&#8217;t care</strong> what the model is, it just uses <code>forward()</code>.</p></li></ol><div><hr></div><h2>How AI Agent Frameworks apply Dynamic Dispatch</h2><p>We started by looking at <strong>VTables in C++</strong>, then saw how <strong>Python uses dynamic dispatch</strong> instead of rigid tables ( &#8220;<strong>rigid table</strong>&#8221; here refers to how <strong>C++ implements polymorphism through a fixed, precomputed structure )</strong>. We also explored <strong>ML frameworks</strong> like PyTorch, where dynamic dispatch lets the training loop call <code>forward()</code> without knowing the exact model.</p><p>Now, the same principle is applied in <em><strong>AI agent frameworks</strong></em> like LangChain, LlamaIndex, and OpenAI agents, extend this idea <strong>one step further.</strong></p><ol><li><p><strong>Interface guarantee</strong>: Each tool provides a known interface (e.g., a <code>run()</code> method).</p></li><li><p><strong>Dynamic method dispatch</strong>: When the agent calls <code>tool.run()</code>, Python dynamically dispatches to the correct implementation just like it does for a model&#8217;s <code>forward()</code> method.</p></li><li><p><strong>Intelligent tool selection</strong>: Unlike a simple loop over tools, the agent can decide at runtime which tool to invoke based on the input. For example, it can pick the <code>MathTool</code> for <code>&#8220;2 + 2&#8221;</code> and <code>SearchTool</code> for <code>&#8220;Python AI frameworks&#8221;</code>. ( check below tool example )</p></li></ol><div class="pullquote"><p>AI frameworks rely heavily on <strong>runtime polymorphism</strong> allowing new behavior to be attached to existing classes <em>dynamically</em>.</p></div><p>So the agent framework is essentially doing <strong>two layers of dynamic dispatch</strong>:</p><ul><li><p><strong>Method-level dispatch</strong>: Python ensures <code>run()</code> of the correct tool is called.</p></li><li><p><strong>Tool-selection dispatch</strong>: The agent&#8217;s reasoning logic decides which tool to use without needing to know in advance.</p></li></ul><blockquote><p><em>The <strong>agent doesn&#8217;t need to know the exact tool ahead of time</strong>, but Python&#8217;s dynamic dispatch ensures the correct method is executed once the agent picks the tool.</em></p></blockquote><h4>1. Tool Definitions (Base + Subclass Analogy)</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XaG_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XaG_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png 424w, https://substackcdn.com/image/fetch/$s_!XaG_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png 848w, https://substackcdn.com/image/fetch/$s_!XaG_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png 1272w, https://substackcdn.com/image/fetch/$s_!XaG_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XaG_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png" width="1456" height="1281" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1281,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:279669,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176186355?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XaG_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png 424w, https://substackcdn.com/image/fetch/$s_!XaG_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png 848w, https://substackcdn.com/image/fetch/$s_!XaG_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png 1272w, https://substackcdn.com/image/fetch/$s_!XaG_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fd6ad2-138f-417b-a7d3-3887cc94d495_1616x1422.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ul><li><p>This part defines the base interface<strong> ( </strong><code>tool</code><strong> )</strong> and specific tools (<code>SearchTool</code>, <code>MathTool</code>).</p></li><li><p>Python dynamic dispatch ensures that <code>func()</code> calls the correct implementation when invoked.</p></li><li><p>Analogous to <strong>base class + subclass in OOP</strong>.</p></li></ul><h4>2. Agent Initialization</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jPCj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jPCj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png 424w, https://substackcdn.com/image/fetch/$s_!jPCj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png 848w, https://substackcdn.com/image/fetch/$s_!jPCj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png 1272w, https://substackcdn.com/image/fetch/$s_!jPCj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jPCj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png" width="1456" height="476" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:476,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:69944,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176186355?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jPCj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png 424w, https://substackcdn.com/image/fetch/$s_!jPCj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png 848w, https://substackcdn.com/image/fetch/$s_!jPCj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png 1272w, https://substackcdn.com/image/fetch/$s_!jPCj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79c80c1-8c73-4c71-8a21-3482ca5c355c_1616x528.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ul><li><p>This part is like the <strong>training loop in ML</strong>: it doesn&#8217;t know the specifics of each tool.</p></li><li><p>The agent is ready to <strong>dynamically pick a tool at runtime</strong> based on input.</p></li></ul><h4>3. Dynamic Tool Invocation (Runtime Dispatch)</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ym1K!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ym1K!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png 424w, https://substackcdn.com/image/fetch/$s_!Ym1K!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png 848w, https://substackcdn.com/image/fetch/$s_!Ym1K!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png 1272w, https://substackcdn.com/image/fetch/$s_!Ym1K!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ym1K!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png" width="1456" height="510" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:510,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:99218,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/176186355?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Ym1K!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png 424w, https://substackcdn.com/image/fetch/$s_!Ym1K!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png 848w, https://substackcdn.com/image/fetch/$s_!Ym1K!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png 1272w, https://substackcdn.com/image/fetch/$s_!Ym1K!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821863bf-f3ae-4e6d-a92a-85eb230129d6_1616x566.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ul><li><p><strong>Layer 1 (Tool Selection)</strong>: Agent decides which tool to call based on the query.</p></li><li><p><strong>Layer 2 (Method Dispatch)</strong>: Python dynamically calls the correct <code>func()</code> of the chosen tool.</p></li><li><p>This mirrors the <strong>ML model forward() dispatch</strong> and the <strong>VTable example</strong>: flexible, runtime method resolution.</p></li></ul><h4><strong>Why Dynamic Dispatch Matters in AI:</strong></h4><ul><li><p><strong>Hardware Abstraction:</strong> AI frameworks like TensorFlow or PyTorch can automatically choose the best code for the hardware you have. For example, a matrix multiplication will run on a GPU if available, or fall back to the CPU otherwise.</p></li><li><p><strong>Polymorphism:</strong> Different types of layers (like ConvolutionalLayer, ReLULayer, DropoutLayer) can each have their own <code>forward()</code> and <code>backward()</code> methods. Dynamic dispatch makes sure the right method runs for each layer at runtime.</p></li><li><p><strong>Flexibility:</strong> AI frameworks need to support many models, layers, and optimizers. Dynamic dispatch lets developers add new features, like a custom activation function, without changing the core code.</p></li></ul><div><hr></div><p><strong>&#129302; </strong><em><strong>AI runs on compute. I run on coffee. Fuel the next post if you enjoyed this one!</strong></em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://buymeacoffee.com/untitledhuman&quot;,&quot;text&quot;:&quot;Buy KK a coffee&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://buymeacoffee.com/untitledhuman"><span>Buy KK a coffee</span></a></p><div><hr></div><h2>Further Readings</h2><p><a href="https://legacy.python.org/workshops/1998-11/proceedings/papers/lowis/lowis.html">https://legacy.python.org/workshops/1998-11/proceedings/papers/lowis/lowis.html</a></p><p><a href="https://python.langchain.com/docs/how_to/callbacks_custom_events/">https://python.langchain.com/docs/how_to/callbacks_custom_events/</a></p>]]></content:encoded></item><item><title><![CDATA[Python 3.14’s No-GIL Explained and Performance Analysis]]></title><description><![CDATA[From threads basics to a real benchmark comparing single-threaded and no-GIL performance.]]></description><link>https://engineersmeetai.substack.com/p/python-314s-no-gil-explained-and</link><guid isPermaLink="false">https://engineersmeetai.substack.com/p/python-314s-no-gil-explained-and</guid><dc:creator><![CDATA[Kannan Kalidasan]]></dc:creator><pubDate>Sat, 11 Oct 2025 16:23:23 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!lioZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Recently, social media like LinkedIn and X have been flooded with posts about Python 3.14 and most of them are release notes summary.</p><p>I don&#8217;t want this article to be another one of those. Instead, let&#8217;s focus on one groundbreaking concept that has the entire Python community excited.</p><p>So, what&#8217;s the big deal?</p><div class="pullquote"><p><strong>Python 3.14</strong> marks a historic milestone that we can run Python <strong>without the Global Interpreter Lock (GIL). </strong></p></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JC2l!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JC2l!,w_424,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif 424w, https://substackcdn.com/image/fetch/$s_!JC2l!,w_848,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif 848w, https://substackcdn.com/image/fetch/$s_!JC2l!,w_1272,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif 1272w, https://substackcdn.com/image/fetch/$s_!JC2l!,w_1456,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JC2l!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif" width="424" height="238.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:270,&quot;width&quot;:480,&quot;resizeWidth&quot;:424,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!JC2l!,w_424,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif 424w, https://substackcdn.com/image/fetch/$s_!JC2l!,w_848,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif 848w, https://substackcdn.com/image/fetch/$s_!JC2l!,w_1272,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif 1272w, https://substackcdn.com/image/fetch/$s_!JC2l!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b497179-613c-416c-8f19-19ae675dc0e9_480x270.gif 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p><strong>What does it means?<br></strong>&#128293; True parallel execution across multiple CPU cores<br>&#9889; Faster multi-threaded performance<br>&#128640; Advantages in data science, AI, and data engineering workloads.</p><p>Let&#8217;s break down what this really means starting from the basics to benchmark comparison and visualize it.</p><h2>Understanding Threads and Concurrency</h2><p>In computing, a <strong>thread is simply a sequence of instructions</strong> that a processor can run independently. A single Python process can have <strong>multiple threads</strong>, each doing some task like reading files, making network calls, or crunching numbers.</p><p>Think of a program like a <strong>recipe</strong>. Some steps can happen at the same time . For example, boiling water while chopping vegetables. Each of those simultaneous activities represents a <strong>thread</strong>. Threads allow a program to handle multiple tasks at once.</p><div class="pullquote"><p>This ability to have different parts of a program run independently is called <strong>concurrency</strong>. </p></div><p>It&#8217;s often achieved through <strong>multithreading</strong>, where a single program creates several threads that appear to run at the same time. True <strong>parallelism</strong> happens only when multiple processor cores execute threads simultaneously. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AwHf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AwHf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png 424w, https://substackcdn.com/image/fetch/$s_!AwHf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png 848w, https://substackcdn.com/image/fetch/$s_!AwHf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png 1272w, https://substackcdn.com/image/fetch/$s_!AwHf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AwHf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png" width="258" height="258" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:372,&quot;width&quot;:372,&quot;resizeWidth&quot;:258,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;CPU Cores vs Threads: Terminology Explained - Rocky MTN Ruby&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="CPU Cores vs Threads: Terminology Explained - Rocky MTN Ruby" title="CPU Cores vs Threads: Terminology Explained - Rocky MTN Ruby" srcset="https://substackcdn.com/image/fetch/$s_!AwHf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png 424w, https://substackcdn.com/image/fetch/$s_!AwHf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png 848w, https://substackcdn.com/image/fetch/$s_!AwHf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png 1272w, https://substackcdn.com/image/fetch/$s_!AwHf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F120004a0-21f3-47b7-a079-84a1127cfb36_372x372.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://rockymtnruby.com/cpu-cores-vs-threads/">A single CPU with 4 cores and 8 threads</a></figcaption></figure></div><p>However, even on a single core, a computer can rapidly switch between threads creating the <em>illusion</em> of parallel execution and making programs feel faster and more responsive.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lioZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lioZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif 424w, https://substackcdn.com/image/fetch/$s_!lioZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif 848w, https://substackcdn.com/image/fetch/$s_!lioZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif 1272w, https://substackcdn.com/image/fetch/$s_!lioZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lioZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif" width="252" height="252" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:500,&quot;width&quot;:500,&quot;resizeWidth&quot;:252,&quot;bytes&quot;:2069344,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/175697815?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!lioZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif 424w, https://substackcdn.com/image/fetch/$s_!lioZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif 848w, https://substackcdn.com/image/fetch/$s_!lioZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif 1272w, https://substackcdn.com/image/fetch/$s_!lioZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd932d54-b46d-40b9-8206-ca234a76004e_500x500.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Source : Giphy</figcaption></figure></div><div><hr></div><h2>The Global Interpreter Lock (GIL)</h2><p>For many years, Python&#8217;s primary implementation, <strong>CPython</strong>, has included a mechanism known as the Global Interpreter Lock (GIL). The GIL is a <strong>mutex</strong> (a type of lock) that protects access to Python objects, ensuring that only one thread can execute Python bytecode at any given time, even on multi-core processors.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8_2Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8_2Z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png 424w, https://substackcdn.com/image/fetch/$s_!8_2Z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png 848w, https://substackcdn.com/image/fetch/$s_!8_2Z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png 1272w, https://substackcdn.com/image/fetch/$s_!8_2Z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8_2Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png" width="1054" height="262" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:262,&quot;width&quot;:1054,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:25712,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/175697815?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8_2Z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png 424w, https://substackcdn.com/image/fetch/$s_!8_2Z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png 848w, https://substackcdn.com/image/fetch/$s_!8_2Z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png 1272w, https://substackcdn.com/image/fetch/$s_!8_2Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a80ac70-ae1f-4427-a56e-87e25fae3b79_1054x262.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Why the GIL Exists?</h3><p>The GIL was originally added to Python to make memory management easier and to prevent race conditions, situations where multiple threads try to change the same data at once. Without the GIL, <strong>CPython&#8217;s memory handling</strong> would be much more complicated and prone to deadlocks or data corruption. At the time, most Python programs were single-threaded, so the GIL made the interpreter simpler, safer, and easier to maintain.</p><h3>How the GIL Works</h3><p>When a Python program runs multiple threads, the GIL ensures that only one thread can execute Python bytecode at a time. <strong>Before running, a thread must first acquire the GIL</strong>. After executing a set number of operations or performing an I/O task, it releases the lock so another thread can take over. As a result, even on a multi-core CPU, only one Python thread can run Python code at any moment and the rest are simply waiting for their turn.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TTI_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TTI_!,w_424,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif 424w, https://substackcdn.com/image/fetch/$s_!TTI_!,w_848,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif 848w, https://substackcdn.com/image/fetch/$s_!TTI_!,w_1272,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif 1272w, https://substackcdn.com/image/fetch/$s_!TTI_!,w_1456,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TTI_!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif" width="512" height="160" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:160,&quot;width&quot;:512,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;undefined&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="undefined" title="undefined" srcset="https://substackcdn.com/image/fetch/$s_!TTI_!,w_424,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif 424w, https://substackcdn.com/image/fetch/$s_!TTI_!,w_848,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif 848w, https://substackcdn.com/image/fetch/$s_!TTI_!,w_1272,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif 1272w, https://substackcdn.com/image/fetch/$s_!TTI_!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c444f1-ca96-4e54-a6f0-2e539f74c114_512x160.gif 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Source : <a href="https://en.wikipedia.org/wiki/Global_interpreter_lock">https://en.wikipedia.org/wiki/Global_interpreter_lock</a></figcaption></figure></div><h3>Performance Implications</h3><h4><strong>CPU-bound tasks</strong></h4><p>The GIL greatly affects Python&#8217;s performance, especially for <strong>CPU-bound tasks, those that spend most of their time doing calculations rather than waiting for I/O</strong>. In these cases, Python&#8217;s multithreading doesn&#8217;t achieve true parallel execution across multiple CPU cores. Instead, threads compete for the GIL, and the constant switching between them can actually make a program slower than a single-threaded one due to context-switching overhead.</p><h4><strong>I/O-bound tasks</strong></h4><p>On the other hand, for I/O-bound tasks such as network requests or file reads, the GIL&#8217;s impact is much smaller. When a thread performs an I/O operation, it usually releases the GIL, allowing other threads to run in the meantime. This makes it possible to achieve good concurrency for I/O-heavy workloads, even with the GIL in place.</p><h2>Python 3.14: (No-GIL) Python</h2><p>After years of R&amp;D, Python 3.14 marks a pivotal moment in Python&#8217;s history: the free-threaded (No-GIL) version of the Python interpreter. </p><p><a href="https://peps.python.org/pep-0703/">PEP 703 &#8211; Making the Global Interpreter Lock Optional in CPython</a></p><p><a href="https://peps.python.org/pep-0779/">PEP 779 &#8211; Criteria for supported status for free-threaded Python</a></p><p><em>This means that developers can now officially leverage Python without the constraints of the Global Interpreter Lock, opening up new possibilities for true parallel execution in multithreaded Python applications.</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0V0Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0V0Z!,w_424,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif 424w, https://substackcdn.com/image/fetch/$s_!0V0Z!,w_848,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif 848w, https://substackcdn.com/image/fetch/$s_!0V0Z!,w_1272,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif 1272w, https://substackcdn.com/image/fetch/$s_!0V0Z!,w_1456,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0V0Z!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif" width="336" height="336" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:480,&quot;width&quot;:480,&quot;resizeWidth&quot;:336,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!0V0Z!,w_424,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif 424w, https://substackcdn.com/image/fetch/$s_!0V0Z!,w_848,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif 848w, https://substackcdn.com/image/fetch/$s_!0V0Z!,w_1272,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif 1272w, https://substackcdn.com/image/fetch/$s_!0V0Z!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88e8122f-3ffe-4d0a-beb8-9a34bbf79844_480x480.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Source : Giphy</figcaption></figure></div><p>CPython&#8217;s internal architecture has undergone major changes, particularly in memory management and object safety, to enable thread-safe execution without depending on a global lock. </p><ul><li><p><strong>True Parallelism:</strong> CPU-bound tasks can finally benefit from multiple cores, potentially leading to significant speedups.</p></li><li><p><strong>Simplified Concurrency Models:</strong> Developers no longer need to rely on multiprocessing (which bypasses the GIL by running separate Python processes) for CPU-bound parallelism, simplifying application design.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0luz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0luz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png 424w, https://substackcdn.com/image/fetch/$s_!0luz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png 848w, https://substackcdn.com/image/fetch/$s_!0luz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png 1272w, https://substackcdn.com/image/fetch/$s_!0luz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0luz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png" width="520" height="328.8681446907818" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:542,&quot;width&quot;:857,&quot;resizeWidth&quot;:520,&quot;bytes&quot;:589082,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/175697815?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0luz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png 424w, https://substackcdn.com/image/fetch/$s_!0luz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png 848w, https://substackcdn.com/image/fetch/$s_!0luz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png 1272w, https://substackcdn.com/image/fetch/$s_!0luz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13e9e111-7d19-4703-9deb-e72dbc371c8f_857x542.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ul><li><p><strong>Improved Responsiveness:</strong> Applications can remain more responsive, as long-running computations in one thread won&#8217;t block other threads from executing.</p></li><li><p><strong>Architecture Changes:</strong></p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9iQ2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9iQ2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png 424w, https://substackcdn.com/image/fetch/$s_!9iQ2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png 848w, https://substackcdn.com/image/fetch/$s_!9iQ2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png 1272w, https://substackcdn.com/image/fetch/$s_!9iQ2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9iQ2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png" width="654" height="298" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:298,&quot;width&quot;:654,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:38742,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/175697815?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9iQ2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png 424w, https://substackcdn.com/image/fetch/$s_!9iQ2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png 848w, https://substackcdn.com/image/fetch/$s_!9iQ2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png 1272w, https://substackcdn.com/image/fetch/$s_!9iQ2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2522c4a2-5e1f-4146-a015-da72edf5d3c8_654x298.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Benchmark Comparison</h2><h4><strong>Prime Number computation</strong></h4><p>Let&#8217;s look at a classic CPU-bound problem, <strong>prime number computation</strong>.<br>This task involves heavy mathematical operations and minimal I/O, making it ideal for testing true parallel execution.</p><ul><li><p><em><strong>My mac configuration:</strong> macOS Sequoia arm64 | Mac mini ( M1, 2020 ) | 16 GB Mem.</em></p></li><li><p><em><strong>Benchmark code</strong> : </em><a href="https://github.com/kannandreams/when-engineers-meet-ai/tree/main/code/python-gil">https://github.com/kannandreams/when-engineers-meet-ai/tree/main/code/python-gil</a></p></li></ul><p><strong>Python == 3.12.10 (with GIL)</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!L0hD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!L0hD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png 424w, https://substackcdn.com/image/fetch/$s_!L0hD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png 848w, https://substackcdn.com/image/fetch/$s_!L0hD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png 1272w, https://substackcdn.com/image/fetch/$s_!L0hD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!L0hD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png" width="770" height="338" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:338,&quot;width&quot;:770,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:66303,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/175697815?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!L0hD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png 424w, https://substackcdn.com/image/fetch/$s_!L0hD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png 848w, https://substackcdn.com/image/fetch/$s_!L0hD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png 1272w, https://substackcdn.com/image/fetch/$s_!L0hD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F895b6e68-8989-49aa-baa1-399b4310a4bb_770x338.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Even though I launched <strong>4 threads</strong>, the total execution time is almost <strong>the same</strong> as the single-threaded version. That&#8217;s because of the <strong>GIL</strong></p><p><strong>Python == 3.14 (no-GIL)</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jAtT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jAtT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png 424w, https://substackcdn.com/image/fetch/$s_!jAtT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png 848w, https://substackcdn.com/image/fetch/$s_!jAtT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png 1272w, https://substackcdn.com/image/fetch/$s_!jAtT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jAtT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png" width="890" height="354" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:354,&quot;width&quot;:890,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:73764,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/175697815?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jAtT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png 424w, https://substackcdn.com/image/fetch/$s_!jAtT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png 848w, https://substackcdn.com/image/fetch/$s_!jAtT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png 1272w, https://substackcdn.com/image/fetch/$s_!jAtT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8b91e96-7de4-4237-843e-d8b63d892a81_890x354.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The below chart shows</p><ul><li><p>Python 3.14t shows significant multi-threading performance gains, with 4-thread execution being 2.8x faster at the largest range.</p></li><li><p>Python 3.12.10 shows minimal benefit from multi-threading, likely due to GIL limitations, with multi-threaded execution being slightly slower.</p></li><li><p>Python 3.14t is consistently faster in both single and multi-threaded scenarios, with the performance gap widening significantly with multi-threading.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JVww!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JVww!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png 424w, https://substackcdn.com/image/fetch/$s_!JVww!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png 848w, https://substackcdn.com/image/fetch/$s_!JVww!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png 1272w, https://substackcdn.com/image/fetch/$s_!JVww!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JVww!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png" width="847" height="538" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:538,&quot;width&quot;:847,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:70417,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/175697815?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JVww!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png 424w, https://substackcdn.com/image/fetch/$s_!JVww!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png 848w, https://substackcdn.com/image/fetch/$s_!JVww!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png 1272w, https://substackcdn.com/image/fetch/$s_!JVww!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6dc792d-ff54-4993-8ccd-9842e8c8c931_847x538.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The below chart shows how much faster multi-threaded (4 threads) execution is compared to single-threaded execution.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uG_f!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uG_f!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png 424w, https://substackcdn.com/image/fetch/$s_!uG_f!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png 848w, https://substackcdn.com/image/fetch/$s_!uG_f!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png 1272w, https://substackcdn.com/image/fetch/$s_!uG_f!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uG_f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png" width="841" height="525" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:525,&quot;width&quot;:841,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:42023,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/175697815?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uG_f!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png 424w, https://substackcdn.com/image/fetch/$s_!uG_f!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png 848w, https://substackcdn.com/image/fetch/$s_!uG_f!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png 1272w, https://substackcdn.com/image/fetch/$s_!uG_f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91ae80a6-2bc4-4188-be10-d9deb5a3f30c_841x525.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ul><li><p><strong>Python 3.14t:</strong> Shows increasing speedup with larger ranges, achieving ~2.8x speedup at 20M primes</p></li><li><p><strong>Python 3.12.10:</strong> Shows speedup close to 1.0x (no improvement), indicating GIL prevents effective parallelization</p><p></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://engineersmeetai.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">When Engineers meet AI is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Mojo🔥: AI Programming Language]]></title><description><![CDATA[Bridging Python's Simplicity with Rust's Performance]]></description><link>https://engineersmeetai.substack.com/p/mojo-ai-programming-language</link><guid isPermaLink="false">https://engineersmeetai.substack.com/p/mojo-ai-programming-language</guid><dc:creator><![CDATA[Kannan Kalidasan]]></dc:creator><pubDate>Sat, 02 Aug 2025 22:11:02 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/4f862b55-500f-4729-8a51-cc2f26fdcdca_2438x1434.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Python is the go-to language for data engineering, analytics, machine learning, and AI. Why? It&#8217;s simple to write, has tons of useful libraries, and allows you to build things quickly. You, me, and all developers love that.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_y57!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_y57!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png 424w, https://substackcdn.com/image/fetch/$s_!_y57!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png 848w, https://substackcdn.com/image/fetch/$s_!_y57!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png 1272w, https://substackcdn.com/image/fetch/$s_!_y57!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_y57!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png" width="438" height="374.26984126984127" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:646,&quot;width&quot;:756,&quot;resizeWidth&quot;:438,&quot;bytes&quot;:433538,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/168997472?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_y57!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png 424w, https://substackcdn.com/image/fetch/$s_!_y57!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png 848w, https://substackcdn.com/image/fetch/$s_!_y57!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png 1272w, https://substackcdn.com/image/fetch/$s_!_y57!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f816a9d-6ce0-4295-b861-d3a9dfc87744_756x646.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://dev.to/codeitbro/15-funniest-and-hilarious-python-coding-memes-2aij"> Image Source</a></figcaption></figure></div><p>Python feels effortless on the surface due to its clean syntax and productivity are a big reason it&#8217;s so popular. But like an iceberg, there&#8217;s a lot hidden underneath. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_OVl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_OVl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png 424w, https://substackcdn.com/image/fetch/$s_!_OVl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png 848w, https://substackcdn.com/image/fetch/$s_!_OVl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png 1272w, https://substackcdn.com/image/fetch/$s_!_OVl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_OVl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png" width="479" height="324.17810026385223" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:513,&quot;width&quot;:758,&quot;resizeWidth&quot;:479,&quot;bytes&quot;:41552,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/168997472?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!_OVl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png 424w, https://substackcdn.com/image/fetch/$s_!_OVl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png 848w, https://substackcdn.com/image/fetch/$s_!_OVl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png 1272w, https://substackcdn.com/image/fetch/$s_!_OVl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038b8119-0300-4798-a6cb-3fddb76010f3_758x513.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>When performance challenge us, the usual reaction is to scale up with more cloud resources instead of optimizing core logic at low level. </p><p>Python struggles with things like parallel execution because of the Global Interpreter Lock (GIL). It lacks strong static typing, offers limited control over low-level operations, and doesn&#8217;t support native GPU execution. While there are just-in-time compilers like PyPy, they&#8217;re not commonly used in the AI ecosystem. </p><h3>Two-Language / Two-World Problem</h3><p>Especially in AI development, things often split into two phases:</p><p>Data scientists and Researchers typically use Python with libraries like NumPy, Pandas, ML Libraries or PyTorch to quickly experiment and build models. It&#8217;s great for prototyping. But when we need to train large models or to deploy those models to production and run them at scale, performance issues start to surface. </p><p><strong>In the end, teams often have to rewrite performance-critical parts of their code in faster, lower-level languages like C++, Rust, or CUDA to run efficiently.</strong></p><blockquote><p>Take PyTorch, for example. Although it is Pythonic interface, many of its core operations and critical components are written in C++ and CUDA.</p><p><em>The <strong><a href="https://docs.pytorch.org/docs/stable/jit.html">torchscript</a></strong> and <strong><a href="https://docs.pytorch.org/tutorials/advanced/cpp_extension.html">custom CUDA extensions</a></strong> are used when Python isn&#8217;t fast enough.</em></p></blockquote><p>This gap between <strong>high-level development</strong> and <strong>low-level optimization</strong> slows teams down. To keep up with the rapid pace of AI, there's also a growing need to optimize for hardware efficiency, energy usage, and adopt AI-native hardware platforms.</p><h3>Imagine Python&#8217;s Simplicity with the Speed of Rust</h3><p>What if we had a language that looked like Python, but was built on a high-performance compiler infrastructure designed to optimize code at the systems level, and to run efficiently on CPUs, GPUs, and other hardware platform without needing to rewrite the code?</p><pre><code>def main() {
    print(<strong>"Hello, World!, Welcome to Mojo"</strong>);
}

# run mojo hello.mojo</code></pre><h2>What is Mojo ?</h2><p><em><strong>Mojo</strong> is a programming language developed by <a href="https://www.modular.com/">Modular Inc</a>., a company co-founded by <a href="https://www.nondot.org/sabre/">Chris Lattner</a>, the creator of <strong>LLVM</strong>, Clang, and the Swift programming language.</em> </p><ul><li><p>MOJO&#8217;s development began with the ambitious goal of creating a <strong>unified language</strong> that could serve the entire AI development lifecycle from initial research and prototyping to production deployment and optimization. </p></li><li><p>The language was designed to be a superset of Python, meaning that existing Python code could run on MOJO with minimal or no modifications, while new code could take advantage of MOJO's advanced performance features when needed.</p></li></ul><p><strong>If I had to define what Mojo is in one line:</strong></p><div class="pullquote"><p><em>&#8220;Rust running on a hardware-agnostic compiler platform&#8221; but built for Python developers.</em></p></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!O3kb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!O3kb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png 424w, https://substackcdn.com/image/fetch/$s_!O3kb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png 848w, https://substackcdn.com/image/fetch/$s_!O3kb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png 1272w, https://substackcdn.com/image/fetch/$s_!O3kb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!O3kb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png" width="831" height="412" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4008915-05ae-4431-a38d-90c677e481bb_831x412.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:412,&quot;width&quot;:831,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:66162,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/168997472?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!O3kb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png 424w, https://substackcdn.com/image/fetch/$s_!O3kb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png 848w, https://substackcdn.com/image/fetch/$s_!O3kb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png 1272w, https://substackcdn.com/image/fetch/$s_!O3kb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4008915-05ae-4431-a38d-90c677e481bb_831x412.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4>Python vs Mojo vs Rust - Speed Test</h4><blockquote><p>Mojo claims to be <strong>68,000 times faster</strong> &#128640; than Python</p></blockquote><p>The following chart shows the avg. time (in secs) it takes to compute the n-th fibonacci number in <strong>Python, Mojo, and Rust</strong> for different values of n:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ozCM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ozCM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp 424w, https://substackcdn.com/image/fetch/$s_!ozCM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp 848w, https://substackcdn.com/image/fetch/$s_!ozCM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp 1272w, https://substackcdn.com/image/fetch/$s_!ozCM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ozCM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp" width="422" height="253.60576923076923" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:875,&quot;width&quot;:1456,&quot;resizeWidth&quot;:422,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;python rust mojo fibo sequence benchmark&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="python rust mojo fibo sequence benchmark" title="python rust mojo fibo sequence benchmark" srcset="https://substackcdn.com/image/fetch/$s_!ozCM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp 424w, https://substackcdn.com/image/fetch/$s_!ozCM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp 848w, https://substackcdn.com/image/fetch/$s_!ozCM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp 1272w, https://substackcdn.com/image/fetch/$s_!ozCM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa45ebbbc-abd3-47ec-9713-e567c2a3630c_1600x961.webp 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://www.statpan.com/2023/10/python-vs-mojo-vs-rust-fibonacci-speed.html">https://www.statpan.com/2023/10/python-vs-mojo-vs-rust-fibonacci-speed.html</a></figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1DdL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1DdL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png 424w, https://substackcdn.com/image/fetch/$s_!1DdL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png 848w, https://substackcdn.com/image/fetch/$s_!1DdL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png 1272w, https://substackcdn.com/image/fetch/$s_!1DdL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1DdL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png" width="598" height="175.1152647975078" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:282,&quot;width&quot;:963,&quot;resizeWidth&quot;:598,&quot;bytes&quot;:54220,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/168997472?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1DdL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png 424w, https://substackcdn.com/image/fetch/$s_!1DdL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png 848w, https://substackcdn.com/image/fetch/$s_!1DdL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png 1272w, https://substackcdn.com/image/fetch/$s_!1DdL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1450cf25-e88e-47d6-8cd3-ceca55011ff7_963x282.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div><hr></div><h2>How Mojo Works?</h2><h3>Architectural Foundations</h3><p>Mojo is built on <strong>MLIR (Multi-Level Intermediate Representation) compiler framework</strong>, which is a key reason it stands out in accelerating Python, especially for AI workloads. </p><p><em>MLIR, <strong>also created by Chris Lattner during his time at Google</strong>, represents a more sophisticated approach to compiler design that allows for multiple levels of abstraction within a single framework. This architecture enables MOJO to perform optimizations that would be difficult or impossible with traditional LLVM-based compilers.</em></p><p>Before we go any further, it&#8217;s important to understand two foundational concepts at a high level: <strong>LLVM and MLIR.</strong> </p><blockquote><p>In the coming months, I plan to publish a detailed blog post that not only explains <strong>&#8220;How LLVM works&#8221;</strong> but also explores the core principles of compiler infrastructure as I continue learning.</p></blockquote><h2><strong>High-Level Overview of LLVM and MLIR</strong></h2><p><strong>LLVM</strong> is a popular compiler infrastructure used by many programming languages. Think of it as a powerful toolkit that helps converting your <strong>high-level code</strong> (like Python) into efficient <strong>machine-level instructions</strong> that computers can run. It&#8217;s great at optimizing code for performance.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ln_E!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ln_E!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png 424w, https://substackcdn.com/image/fetch/$s_!Ln_E!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png 848w, https://substackcdn.com/image/fetch/$s_!Ln_E!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png 1272w, https://substackcdn.com/image/fetch/$s_!Ln_E!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ln_E!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png" width="1456" height="286" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:286,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:90638,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/168997472?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Ln_E!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png 424w, https://substackcdn.com/image/fetch/$s_!Ln_E!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png 848w, https://substackcdn.com/image/fetch/$s_!Ln_E!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png 1272w, https://substackcdn.com/image/fetch/$s_!Ln_E!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d37ec4d-2b78-4e4f-a652-69663479c5c4_1893x372.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>MLIR builds on LLVM</strong> but takes a step further. Instead of working with just one low-level representation of code, MLIR introduces <strong>multiple levels of intermediate representations.</strong> This multi-level design makes it easier to handle complex programming tasks, support new languages, and optimize code across different hardware platforms.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qigD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qigD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png 424w, https://substackcdn.com/image/fetch/$s_!qigD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png 848w, https://substackcdn.com/image/fetch/$s_!qigD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png 1272w, https://substackcdn.com/image/fetch/$s_!qigD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qigD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png" width="1387" height="742" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:742,&quot;width&quot;:1387,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:133467,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/168997472?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qigD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png 424w, https://substackcdn.com/image/fetch/$s_!qigD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png 848w, https://substackcdn.com/image/fetch/$s_!qigD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png 1272w, https://substackcdn.com/image/fetch/$s_!qigD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F495f9acb-1842-4e0f-a2f6-dfc6c718719f_1387x742.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Hardware-Agnostic Approach</h3><p>Mojo, built on MLIR, uses multi-level intermediate representations (IRs) to target a wide range of hardware, including:</p><ul><li><p>General-purpose CPUs</p></li><li><p>Parallel and accelerated processors like GPUs, TPUs, and NPUs</p></li><li><p>Custom hardware such as FPGAs and ASICs</p></li><li><p>Emerging computing platforms like QPUs</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!c-0a!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!c-0a!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png 424w, https://substackcdn.com/image/fetch/$s_!c-0a!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png 848w, https://substackcdn.com/image/fetch/$s_!c-0a!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png 1272w, https://substackcdn.com/image/fetch/$s_!c-0a!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!c-0a!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png" width="1200" height="310.7142857142857" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:377,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:50164,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/168997472?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-large" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!c-0a!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png 424w, https://substackcdn.com/image/fetch/$s_!c-0a!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png 848w, https://substackcdn.com/image/fetch/$s_!c-0a!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png 1272w, https://substackcdn.com/image/fetch/$s_!c-0a!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2912b5d7-d91d-4fa0-9d2c-4be133d09f0b_1628x422.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Because of MLIR, developers don&#8217;t need to learn different programming styles for each type of hardware. Unlike CUDA, which only works with NVIDIA GPUs and has its own programming language, Mojo can generate optimized code for many kinds of devices, all from the same simple code.</p><p><strong>&#128204; This hardware-agnostic approach is particularly valuable as the AI hardware landscape continues to diversify. Companies like AMD, Intel, and many startups are developing specialized AI chips, and cloud providers are offering their own custom silicon (specialized semiconductor chips) for machine learning workloads.</strong> This is a significant advantage for anyone looking to avoid vendor lock-in or optimize for specific hardware configurations.</p><div><hr></div><h2><strong>Key Features of Mojo</strong></h2><p>MOJO's design philosophy is to provide developers with the flexibility to choose their level of abstraction and performance optimization. This approach is manifested through several key features that distinguish it from both traditional Python and other high-performance programming languages.</p><h4>1. <a href="https://docs.modular.com/mojo/manual/functions/">Dual Functions : def </a><strong><a href="https://docs.modular.com/mojo/manual/functions/">vs</a></strong><a href="https://docs.modular.com/mojo/manual/functions/"> fn</a></h4><p>Mojo supports two keywords to declare functions: <code>def</code> and <code>fn</code>.</p><p>Use <code>def</code> for Python-style dynamic functions, or <code>fn</code> when you want higher performance and stricter behavior.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hrNj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hrNj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png 424w, https://substackcdn.com/image/fetch/$s_!hrNj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png 848w, https://substackcdn.com/image/fetch/$s_!hrNj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png 1272w, https://substackcdn.com/image/fetch/$s_!hrNj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hrNj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png" width="784" height="162" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:162,&quot;width&quot;:784,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:34010,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/168997472?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hrNj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png 424w, https://substackcdn.com/image/fetch/$s_!hrNj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png 848w, https://substackcdn.com/image/fetch/$s_!hrNj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png 1272w, https://substackcdn.com/image/fetch/$s_!hrNj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcb2948d-c9a4-4b15-9aaf-40175b7ab80e_784x162.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h4><strong>2. <a href="https://docs.modular.com/mojo/manual/values/ownership/">Memory Management and the Borrow Checker</a></strong></h4><p>Mojo offers a streamlined approach to memory management, inspiration from <strong>Rust's ownership system</strong> to ensure memory safety without the performance cost of garbage collection.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iaYf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iaYf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg 424w, https://substackcdn.com/image/fetch/$s_!iaYf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg 848w, https://substackcdn.com/image/fetch/$s_!iaYf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!iaYf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iaYf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg" width="600" height="308.65384615384613" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:749,&quot;width&quot;:1456,&quot;resizeWidth&quot;:600,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iaYf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg 424w, https://substackcdn.com/image/fetch/$s_!iaYf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg 848w, https://substackcdn.com/image/fetch/$s_!iaYf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!iaYf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F886ef975-851a-4719-ba30-998f9b8f16ee_1900x978.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://www.turingtaco.com/exploring-the-ai-trading-strategies-course-using-mojo-2/">image source link</a></figcaption></figure></div><ul><li><p>Mojo's memory management is a <strong>&#8220;borrow checker&#8221;</strong> that analyzes code as it is compiled. This tool prevents common memory-related bugs such as using memory after it has been freed, freeing memory twice, and data races. </p></li><li><p>The goal is to provide these safety guarantees in a way that is more user-friendly for Python developers and provide clear error messages to fix memory issues quickly.</p></li></ul><h4>3. <a href="https://docs.modular.com/mojo/stdlib/algorithm/functional/parallelize/">Automatic Vectorization and Parallelization</a></h4><ul><li><p>Mojo has built-in features to manage concurrent operations and makes parallel programming easier by providing built-in tools take full advantage of hardware.</p></li><li><p>It automatically manages threads and uses SIMD ( <strong>Single instruction, multiple data</strong> ) vectorization, so developers can concentrate on their program&#8217;s logic without worrying about low-level details. </p></li></ul><p>For example, its <strong><a href="https://docs.modular.com/mojo/stdlib/algorithm/functional/parallelize/">parallelize</a></strong> function efficiently splits loop iterations across multiple CPU cores, which is perfect for tasks that can run in parallel on data.</p><p>Below sample code using <code>parallelize</code> in Mojo that squares each element of an array in parallel using all available CPU cores.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tit2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tit2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png 424w, https://substackcdn.com/image/fetch/$s_!tit2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png 848w, https://substackcdn.com/image/fetch/$s_!tit2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png 1272w, https://substackcdn.com/image/fetch/$s_!tit2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tit2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png" width="579" height="247.7539184952978" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:546,&quot;width&quot;:1276,&quot;resizeWidth&quot;:579,&quot;bytes&quot;:89756,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/168997472?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tit2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png 424w, https://substackcdn.com/image/fetch/$s_!tit2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png 848w, https://substackcdn.com/image/fetch/$s_!tit2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png 1272w, https://substackcdn.com/image/fetch/$s_!tit2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff93f3ef9-aa5c-46cc-bab2-9f061c65df9a_1276x546.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4>4. <a href="https://docs.modular.com/mojo/manual/structs/">Struct-Based Object Model</a></h4><p><strong>Mojo's </strong><code>struct</code><strong> is similar to Rust&#8217;s struct</strong>, designed for speed, safety, and low-level control. </p><p>Unlike Python classes, Mojo structs are value types with a fixed layout known at compile time. This makes them highly efficient for performance-critical tasks like AI and systems programming. Yet, they retain object-oriented features like methods and operator overloading.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4ZfM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4ZfM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png 424w, https://substackcdn.com/image/fetch/$s_!4ZfM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png 848w, https://substackcdn.com/image/fetch/$s_!4ZfM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png 1272w, https://substackcdn.com/image/fetch/$s_!4ZfM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4ZfM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png" width="583" height="174" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:174,&quot;width&quot;:583,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:18799,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://engineersmeetai.substack.com/i/168997472?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4ZfM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png 424w, https://substackcdn.com/image/fetch/$s_!4ZfM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png 848w, https://substackcdn.com/image/fetch/$s_!4ZfM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png 1272w, https://substackcdn.com/image/fetch/$s_!4ZfM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a097693-4742-435a-8cd0-e5d2165b9ece_583x174.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div><hr></div><h3>Mojo&#8217;s Use Cases</h3><ul><li><p><strong>AI Workflow &amp; Edge AI:</strong> Mojo optimizes tensor operations, backpropagation, and gradient descent during training. Its efficient runtime and hardware-agnostic codegen make it ideal for edge AI, real-time systems, and model serving.</p></li><li><p><strong>Systems Programming for AI Infrastructure:</strong> Mojo isn&#8217;t just for model code. It can also power AI infrastructure like data pipelines, custom drivers, and high-performance runtimes.</p></li></ul><h3>References</h3><ol><li><p><a href="https://mlir.llvm.org/">Multi-Level IR Compiler Framework</a></p></li><li><p><a href="https://www.modular.com/mojo">Mojo: Powerful CPU+GPU Programming</a></p></li><li><p><strong>Why Mojo</strong> - <a href="https://docs.modular.com/mojo/why-mojo">https://docs.modular.com/mojo/why-mojo</a></p></li><li><p><a href="https://www.codecademy.com/article/understanding-the-global-interpreter-lock-gil-in-python">Understanding the Global Interpreter Lock in Python</a></p></li><li><p><a href="https://www.modular.com/blog/mojo-vs-rust">Mojo vs. Rust: what are the differences?</a></p></li><li><p><a href="https://www.statpan.com///python-vs-mojo-vs-rust-fibonacci-speed.html">Python vs Mojo vs Rust: A Fibonacci Speed Test</a> </p></li></ol><div><hr></div><p><strong>&#128161; </strong><em><strong>Enjoyed this post? A coffee helps fuel the next one!</strong></em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://buymeacoffee.com/untitledhuman&quot;,&quot;text&quot;:&quot;Buy KK a coffee&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://buymeacoffee.com/untitledhuman"><span>Buy KK a coffee</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Service, Handlers and Controllers - Explained]]></title><description><![CDATA[In a typical Go or take any backend project, you might come across three common folders: service, handler, and controller. Each of these folders serves a distinct purpose and plays a specific role in the project's architecture. Here's a brief explanation of each folder and their differences:]]></description><link>https://engineersmeetai.substack.com/p/service-handlers-controllers-in-go</link><guid isPermaLink="false">https://engineersmeetai.substack.com/p/service-handlers-controllers-in-go</guid><dc:creator><![CDATA[Kannan Kalidasan]]></dc:creator><pubDate>Tue, 28 Feb 2023 19:20:16 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ImEf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In a typical Go or take any backend project, you might come across three common folders: <code>service</code>, <code>handler</code>, and <code>controller</code>. Each of these folders serves a distinct purpose and plays a specific role in the project's architecture. Here's a brief explanation of each folder and their differences:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ImEf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ImEf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg 424w, https://substackcdn.com/image/fetch/$s_!ImEf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg 848w, https://substackcdn.com/image/fetch/$s_!ImEf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!ImEf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ImEf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg" width="1019" height="422" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:422,&quot;width&quot;:1019,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:90761,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://eggpuffengineer.substack.com/i/105663142?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a438da6-84e4-4713-9082-ae323d5344c4_1024x768.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ImEf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg 424w, https://substackcdn.com/image/fetch/$s_!ImEf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg 848w, https://substackcdn.com/image/fetch/$s_!ImEf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!ImEf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eec97fe-5163-4b58-95e6-e1b3d5fde392_1019x422.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3><code>The Service</code></h3><p>The <code>service</code> folder usually contains the business logic of the application. It is responsible for performing operations that the application is designed to do. For instance, in a simple e-commerce application, a <code>service</code> might handle functions such as adding or removing products from the cart, placing an order, processing payment, and updating the order status.</p><p>Here is an example of a simple <code>service</code> function in Go:</p><pre><code>package service

func PlaceOrder(order Order) error {
    // Validate order details
    // Process payment
    // Update order status
    // Send confirmation email to the user
    return nil
}</code></pre><h3><code>The Handler</code></h3><p>The <code>handler</code> folder typically contains the HTTP request handlers. These handlers are responsible for receiving HTTP requests from the user, performing any necessary validation or parsing, and then passing control to the appropriate <code>service</code> function.</p><p>Here is an example of a simple <code>handler</code> function in Go:</p><pre><code>package handler

func PlaceOrderHandler(w http.ResponseWriter, r *http.Request) {
    // Parse order details from the request body
    // Call the PlaceOrder function from the service package
    // Return appropriate response to the user
}</code></pre><h3><code>The Controller</code></h3><p>The <code>controller</code> folder typically contains the functions responsible for handling user input, such as form data or user input data from the command line. These functions parse the input data, validate it, and then call the appropriate <code>service</code> function to perform the desired operation.</p><p>Here is an example of a simple <code>controller</code> function in Go:</p><pre><code>package controller

func PlaceOrderController() {
    // Prompt user to input order details
    // Parse and validate the input
    // Call the PlaceOrder function from the service package
    // Display appropriate response to the user
}
</code></pre><h3><strong>How the process works</strong></h3><ol><li><p>When the user submits a form or clicks a button on a web page, an HTTP request is sent to the server.</p></li><li><p>The request is routed to the appropriate handler function based on the URL or route specified in the request.</p></li><li><p>The handler function receives the request and any associated data, such as form data or URL parameters.</p></li><li><p>The handler function then passes the data to the appropriate service function to perform any necessary business logic.</p></li><li><p>The service function performs any necessary operations, such as saving data to a database or performing calculations, and returns the result to the handler function.</p></li><li><p>The handler function then returns an HTTP response to the user, typically in the form of an HTML page or JSON data.</p></li><li><p>If there are any errors or exceptions during this process, they are handled appropriately, such as by returning an error message to the user or logging the error for later analysis.</p></li></ol><p>The controller function acts as an interface between the front-end and the backend, handling user input and calling the appropriate handler function to process the request. The handler function is responsible for handling the HTTP request and invoking the appropriate service function to perform any necessary business logic. Finally, the response is returned to the controller function, which can then display the appropriate response to the user on the front-end.</p><p>So, in summary, the process involves a request being handled by the appropriate handler function, which calls the necessary service function to perform any business logic, and returns a response to the controller function, which can then display the result to the user on the front-end.</p><h4><strong>Does Router consider as Controller?</strong></h4><p>The router can be thought of as a part of the controller layer, as it is responsible for routing incoming HTTP requests to the appropriate handler function based on the URL or route specified in the request.</p><p>However, in the context of a typical MVC (Model-View-Controller) architecture, the router would be considered a part of the infrastructure or framework layer, rather than the controller layer.</p><p>The controller layer is typically responsible for handling user input and managing the flow of data between the front-end and the backend. This includes tasks such as validation, authentication, and authorization.</p><p>The handler functions are responsible for handling HTTP requests and invoking the appropriate service function to perform any necessary business logic.</p><p>So, while the router can be considered a part of the controller layer in the sense that it routes requests to the appropriate handler function, it is not typically considered to be a part of the controller layer in the context of a typical MVC architecture.</p><h3><strong>Advantage of using Controller?</strong></h3><p>By using a controller, we can separate the handling of HTTP requests from the business logic of the application. The controller handles tasks such as parsing request parameters, performing validation, and returning appropriate HTTP responses to the client. The handler function is responsible for performing the actual business logic of the application.</p><p>This separation of concerns makes the code more modular, easier to test, and easier to maintain. It also allows for more flexibility in the application design, as different controllers can be used to handle different types of HTTP requests or to interact with different parts of the application.</p><p>Additionally, using a controller allows us to encapsulate any application-specific logic, such as authentication or authorization, within the controller layer. This can help to keep the business logic layer more focused on the core functionality of the application.</p><p>So, while it is possible to call the handler function directly from the HTTP request handler, using a controller provides an additional layer of abstraction that can be beneficial for the overall design and maintainability of the application.</p><p><strong>Organize these components in Go project</strong></p><pre><code>myapp/
&#9500;&#9472;&#9472; cmd/
&#9474;   &#9500;&#9472;&#9472; main.go
&#9474;   &#9492;&#9472;&#9472; ...
&#9500;&#9472;&#9472; internal/
&#9474;   &#9500;&#9472;&#9472; config/
&#9474;   &#9474;   &#9500;&#9472;&#9472; config.go
&#9474;   &#9474;   &#9492;&#9472;&#9472; ...
&#9474;   &#9500;&#9472;&#9472; controllers/
&#9474;   &#9474;   &#9500;&#9472;&#9472; user_controller.go
&#9474;   &#9474;   &#9492;&#9472;&#9472; ...
&#9474;   &#9500;&#9472;&#9472; handlers/
&#9474;   &#9474;   &#9500;&#9472;&#9472; user_handler.go
&#9474;   &#9474;   &#9492;&#9472;&#9472; ...
&#9474;   &#9500;&#9472;&#9472; models/
&#9474;   &#9474;   &#9500;&#9472;&#9472; user.go
&#9474;   &#9474;   &#9492;&#9472;&#9472; ...
&#9474;   &#9500;&#9472;&#9472; services/
&#9474;   &#9474;   &#9500;&#9472;&#9472; user_service.go
&#9474;   &#9474;   &#9492;&#9472;&#9472; ...
&#9474;   &#9492;&#9472;&#9472; ...
&#9500;&#9472;&#9472; static/
&#9474;   &#9500;&#9472;&#9472; css/
&#9474;   &#9474;   &#9492;&#9472;&#9472; ...
&#9474;   &#9500;&#9472;&#9472; js/
&#9474;   &#9474;   &#9492;&#9472;&#9472; ...
&#9474;   &#9492;&#9472;&#9472; ...
&#9500;&#9472;&#9472; templates/
&#9474;   &#9500;&#9472;&#9472; index.html
&#9474;   &#9492;&#9472;&#9472; ...
&#9492;&#9472;&#9472; ...</code></pre>]]></content:encoded></item></channel></rss>