<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by vansh5632 on Medium]]></title>
        <description><![CDATA[Stories by vansh5632 on Medium]]></description>
        <link>https://medium.com/@vanshgilhotra8885?source=rss-0a39dbe31844------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6IMya23slqiWM6rz</url>
            <title>Stories by vansh5632 on Medium</title>
            <link>https://medium.com/@vanshgilhotra8885?source=rss-0a39dbe31844------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:49:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vanshgilhotra8885/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding Turbopack]]></title>
            <link>https://medium.com/@vanshgilhotra8885/understanding-turbopack-0cb2c962ff23?source=rss-0a39dbe31844------2</link>
            <guid isPermaLink="false">https://medium.com/p/0cb2c962ff23</guid>
            <category><![CDATA[turbopack]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[vansh5632]]></dc:creator>
            <pubDate>Sun, 23 Nov 2025 14:28:52 GMT</pubDate>
            <atom:updated>2025-11-23T14:28:52.161Z</atom:updated>
            <content:encoded><![CDATA[<p>Anything you see on the web today isn’t just natively built in raw HTML, CSS, and JS. These sites are built with very cool frameworks (like React, Vue, or Svelte) which rely on much more complex dependency systems.</p><p><strong>Have you ever wondered how these complex things are actually presented in the browser?</strong></p><p>Your project, whether in Next.js or React, is first processed by a <strong>Module Bundler</strong> (like Webpack or the new Turbopack). It builds a graph of all your dependencies, applies different techniques/transformations, and finally bundles them. In simple language: it converts your code into a form the browser can actually load.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M2Bc1mWKKjpR9-xVirUTqQ.png" /></figure><p>Today, let’s talk about the new beast in town: <strong>Turbopack</strong>.</p><h3>What is Turbopack?</h3><p>It is a high-performance build system designed specifically for JavaScript and TypeScript codebases, developed by <strong>Vercel</strong>.</p><p>While it is part of the “Turbo” ecosystem (which includes Turborepo for managing monorepos), Turbopack is laser-focused on the bundling process. The main objective of building this system is to push the performance of the Next.js framework to the absolute limit.</p><p><strong>A Quick Clarification: The Turbo Family</strong> Before we dig deeper, it’s easy to confuse <strong>Turbopack</strong> with its sibling, <strong>Turborepo</strong>.</p><ul><li><strong>Turborepo</strong> is a smart “Task Runner” — it makes sure you don’t re-run tests or linting commands if code hasn’t changed.</li><li><strong>Turbopack</strong> is the “Bundler” — it handles the actual code and assets.</li></ul><p>The cool part? They both share the same brain: the <strong>Turbo Engine</strong>. Turbopack inherits that same “smart caching” logic that made Turborepo famous, but applies it specifically to compiling your JavaScript and TypeScript files.</p><p><strong>Why is it special?</strong></p><ul><li><strong>Written in Rust:</strong> It leverages low-level memory management and multi threading.</li><li><strong>Faster than Webpack:</strong> It is designed to replace Webpack.</li><li><strong>Open Source:</strong> It’s community-driven.</li><li><strong>Smart Caching:</strong> It works by strictly adhering to the rule: <em>Never do the same work twice.</em></li></ul><h3>How it Works: The “Rust Magic”</h3><p>Turbopack achieves its speed using a few really cool architectural decisions:</p><h4>1. The Unified Graph</h4><p>Assume you are using multiple systems at once (Client side, Server side, Edge functions). In older tools, it became very difficult to manage these different contexts. Turbopack uses a <strong>Single, Unified Graph</strong> for all environments. It doesn’t treat them as separate worlds; it understands how they link together.</p><h4>2. Lazy Bundling</h4><p>Turbopack does not rely on Native ESM (like Vite does), nor does it bundle everything at once (like Webpack). Instead, it uses <strong>Lazy Bundling</strong>. It only bundles what is actually requested by the dev server. If you are working on the “About” page, Turbopack won’t waste time compiling the “Contact” page until you actually navigate there. This drastically reduces initial compile times and memory usage.</p><p><strong>But wait, doesn’t Vite already do this?</strong> You might be thinking, <em>“I already use Vite and it’s super fast, why do I need this?”</em></p><p>Modern developers love Vite, and for good reason. Vite gets its speed by using native ESM — essentially serving your files one-by-one directly to the browser. This is fantastic for small to medium projects.</p><p><strong>The Problem:</strong> When you have a massive enterprise application with thousands of modules, Vite can hit a “network bottleneck.” The browser gets overwhelmed trying to download thousands of tiny files individually.</p><p><strong>The Turbopack Solution:</strong> Turbopack claims to scale better on these massive projects because it doesn’t just serve raw files; it <strong>bundles them lazily</strong>. It stitches the code together on the server side (just for the parts you need), so the browser receives fewer, larger chunks. This avoids the network jam, keeping the app snappy even if you have 50,000 components</p><h4>3. The Turbo Engine &amp; Incremental Computation</h4><p>This is where the real magic happens. Vercel built a custom library called the <strong>Turbo Engine</strong>.</p><p>It treats every single step in your build — parsing a file, resolving an import, compiling a module — as a <strong>Pure Function</strong> call in Rust. This leads us to the secret sauce:</p><h4>4. The Red-Green Algorithm</h4><p>This is a specific algorithm (borrowed from the Rust compiler itself) that makes Turbopack incredibly efficient.</p><p><strong>Imagine this scenario:</strong> You have a file Button.tsx that imports Icon.tsx.</p><ol><li>You change a comment in Icon.tsx.</li><li>Turbopack sees the file changed and marks the function compile(&quot;Icon.tsx&quot;) as <strong>Dirty (Red)</strong>.</li><li>It re-runs the compilation for just that file.</li><li><strong>The Magic:</strong> If the output of that compilation (the binary code) is identical to the previous run (e.g., you only changed a comment or whitespace), Turbopack marks the node as <strong>Green</strong> again.</li></ol><p>Because it is now “Green,” Turbopack <strong>stops</strong>. It does not re-compile Button.tsx (the parent) because it knows the dependency hasn&#39;t <em>effectively</em> changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*H2_6Ys3-LUNgNoXK8VfcJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HSx7i_xiEvTZPaCdkB0xqg.png" /></figure><p>Refrences<br><a href="https://nextjs.org/docs/app/api-reference/turbopack">https://nextjs.org/docs/app/api-reference/turbopack</a></p><p><a href="http://youtube.com/watch?v=6ZwnBI4Rb1w&amp;start=0">youtube.com/watch?v=6ZwnBI4Rb1w&amp;start=0</a></p><p><a href="https://github.com/vercel/turborepo">https://github.com/vercel/turborepo</a></p><p><a href="https://vite.dev/guide/">https://vite.dev/guide/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0cb2c962ff23" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>