---
title: "50KB Down to 2KB: Why We Stopped Parsing Source Files"
date: 2026-05-28
type: post
tags: [bundler, performance, cloudpack, parsing, caching]
summary: "A typical TypeScript source file is 50KB. Its module summary is 2KB. At 50,000 modules that's the difference between 2.5GB and 100MB. The 100MB fits in L3 cache. The 2.5GB doesn't."
---

A typical TypeScript module in a large codebase is about 50KB of source text. Imports, exports, JSX, type annotations, function bodies, comments. The bundler parses all of it on every build. Then it throws away everything except the dependency edges.

That's the waste. A bundler's graph analysis only cares about five things: what does this module export, what does it import, does it have side effects, what calls what, and does it touch any globals. That information fits in about 2KB. The other 48KB is function bodies, JSX markup, and type annotations that the graph never looks at.

At 100 modules, nobody notices. At 50,000 modules, the difference is 2.5GB versus 100MB. One fits in an L3 cache. The other doesn't fit in RAM on half the laptops in your organization.

## The struct that replaces parsing

Every source file gets reduced to a `ModuleSummary`. This is the actual Rust struct from the [Cloudpack summarizer](https://github.com/nicolo-ribaudo/tc39-proposal-structs):

```rust
pub struct ModuleSummary {
    pub exports: Vec<Export>,
    pub imports: Vec<Import>,
    pub side_effects: SideEffectMarker,
    pub call_edges: Vec<CallEdge>,
    pub ambient_refs: Vec<String>,
}
```

Five fields. Exports: what names does this module make available. Imports: what specifiers does it pull in, and which bindings. Side effects: can the bundler skip this module if nothing imports from it. Call edges: which exported function calls which other exported function, so the tree-shaker can reason about cross-function reachability. Ambient refs: does this module touch `window`, `document`, or `globalThis`.

That's everything Phase 2 (the graph analysis) needs. It never reads source text. It operates on summaries only.

<div class="breakout">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 840 420" role="img" aria-label="Diagram: Source File vs Module Summary, showing 25x compression from 50KB of source to 2KB of summary by discarding function bodies, JSX, types, and comments">
  <rect width="840" height="420" fill="#F5F0E8" rx="4"/>
  <text x="420" y="32" text-anchor="middle" font-family="Georgia, serif" font-size="16" font-weight="bold" fill="#2B2421">Source File vs Module Summary</text>
  <rect x="40" y="56" width="340" height="320" rx="4" fill="none" stroke="#2B2421" stroke-width="1.5"/>
  <text x="210" y="80" text-anchor="middle" font-family="Inter, sans-serif" font-size="14" font-weight="600" fill="#2B2421">Source File (~50KB)</text>
  <rect x="60" y="96" width="300" height="32" rx="3" fill="#A0522D" stroke="none"/>
  <text x="210" y="117" text-anchor="middle" font-family="monospace" font-size="11" font-weight="bold" fill="#F5F0E8">import / export declarations</text>
  <rect x="60" y="136" width="300" height="32" rx="3" fill="#A0522D" stroke="none" opacity="0.8"/>
  <text x="210" y="157" text-anchor="middle" font-family="monospace" font-size="11" font-weight="bold" fill="#F5F0E8">side-effect statements</text>
  <rect x="60" y="176" width="300" height="28" rx="3" fill="#A0522D" stroke="none" opacity="0.6"/>
  <text x="210" y="195" text-anchor="middle" font-family="monospace" font-size="11" font-weight="bold" fill="#F5F0E8">call edges between exports</text>
  <rect x="60" y="212" width="300" height="28" rx="3" fill="#A0522D" stroke="none" opacity="0.4"/>
  <text x="210" y="231" text-anchor="middle" font-family="monospace" font-size="11" font-weight="bold" fill="#F5F0E8">ambient refs (window, document)</text>
  <rect x="60" y="252" width="300" height="108" rx="3" fill="none" stroke="#2B2421" stroke-width="1" stroke-dasharray="5,3"/>
  <text x="210" y="278" text-anchor="middle" font-family="monospace" font-size="11" fill="#2B2421">function bodies</text>
  <text x="210" y="296" text-anchor="middle" font-family="monospace" font-size="11" fill="#2B2421">JSX markup</text>
  <text x="210" y="314" text-anchor="middle" font-family="monospace" font-size="11" fill="#2B2421">type annotations</text>
  <text x="210" y="332" text-anchor="middle" font-family="monospace" font-size="11" fill="#2B2421">comments</text>
  <text x="210" y="352" text-anchor="middle" font-family="Georgia, serif" font-size="11" font-style="italic" fill="#A0522D">discarded (96% of bytes)</text>
  <line x1="390" y1="216" x2="450" y2="216" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow1)"/>
  <text x="420" y="206" text-anchor="middle" font-family="Georgia, serif" font-size="11" fill="#2B2421">25x</text>
  <rect x="460" y="56" width="340" height="188" rx="4" fill="none" stroke="#2B2421" stroke-width="1.5"/>
  <text x="630" y="80" text-anchor="middle" font-family="Inter, sans-serif" font-size="14" font-weight="600" fill="#2B2421">Module Summary (~2KB)</text>
  <rect x="480" y="96" width="300" height="28" rx="3" fill="#A0522D" stroke="none"/>
  <text x="630" y="115" text-anchor="middle" font-family="monospace" font-size="11" font-weight="bold" fill="#F5F0E8">exports: Vec&lt;Export&gt;</text>
  <rect x="480" y="130" width="300" height="28" rx="3" fill="#A0522D" stroke="none" opacity="0.8"/>
  <text x="630" y="149" text-anchor="middle" font-family="monospace" font-size="11" font-weight="bold" fill="#F5F0E8">imports: Vec&lt;Import&gt;</text>
  <rect x="480" y="164" width="300" height="28" rx="3" fill="#A0522D" stroke="none" opacity="0.6"/>
  <text x="630" y="183" text-anchor="middle" font-family="monospace" font-size="11" font-weight="bold" fill="#F5F0E8">side_effects: SideEffectMarker</text>
  <rect x="480" y="198" width="146" height="28" rx="3" fill="#A0522D" stroke="none" opacity="0.4"/>
  <text x="553" y="217" text-anchor="middle" font-family="monospace" font-size="11" font-weight="bold" fill="#F5F0E8">call_edges</text>
  <rect x="634" y="198" width="146" height="28" rx="3" fill="#A0522D" stroke="none" opacity="0.4"/>
  <text x="707" y="217" text-anchor="middle" font-family="monospace" font-size="11" font-weight="bold" fill="#F5F0E8">ambient_refs</text>
  <rect x="460" y="280" width="340" height="96" rx="4" fill="none" stroke="#2B2421" stroke-width="1"/>
  <text x="630" y="304" text-anchor="middle" font-family="Georgia, serif" font-size="13" fill="#2B2421">At 50,000 modules:</text>
  <text x="630" y="326" text-anchor="middle" font-family="monospace" font-size="12" fill="#2B2421">Sources: 50,000 x 50KB = 2.5GB</text>
  <text x="630" y="346" text-anchor="middle" font-family="monospace" font-size="12" font-weight="bold" fill="#A0522D">Summaries: 50,000 x 2KB = 100MB</text>
  <text x="630" y="366" text-anchor="middle" font-family="Georgia, serif" font-size="12" font-style="italic" fill="#2B2421">100MB fits in L3 cache</text>
  <defs>
    <marker id="arrow1" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto">
      <polygon points="0 0, 8 3, 0 6" fill="#2B2421"/>
    </marker>
  </defs>
</svg>
</div>

## How the summarizer sees side effects

The hardest field to compute is `side_effects`. A module with side effects can't be tree-shaken even if nothing imports from it, because removing it might change program behavior. The `SideEffectMarker` has three states:

```rust
pub enum SideEffectMarker {
    None,                         // safe to eliminate
    Possible { reason: String },  // heuristic: maybe
    Definite,                     // must keep
}
```

The analyzer walks every top-level statement in the SWC AST. Import and export declarations are never side effects. Function, class, and type declarations are pure. Variable declarations are pure only when every initializer is a literal, an arrow function, or an identifier.

Anything else gets flagged. A top-level expression statement like `console.log('hello')` is `Possible`. An assignment to `window.APP_VERSION = '2.0.0'` is `Definite`, because the module writes to a known ambient global.

The globals list is short and explicit:

```rust
const AMBIENT_GLOBALS: &[&str] = &[
    "window", "document", "globalThis",
    "global", "self", "navigator",
];
```

No heuristics, no LLM, no annotations. Walk the AST, classify the top-level, report. The entire [side-effect analyzer](https://github.com/nicolo-ribaudo/tc39-proposal-structs) is 86 lines of Rust. The conservative default is correct: if you're uncertain, mark it `Possible` and let Phase 2 keep the module.

## The two-tier cache

A summary only needs to be computed once per unique source file. The cache key is `SHA-256(source)`:

```rust
let source = fs::read_to_string(path)?;
let hash = ContentHash::from_source(&source);
```

Same content, same hash, same summary. Rename the file, move it to a different directory, copy it into another package. The summary is the same because the source bytes are the same. This is the content-addressed property: identity follows content, not path.

The cache has two tiers:

**File-level (the default).** Every source file under active development is cached by `SHA-256(source)`. Change one character, the hash changes, the summarizer re-parses. Change nothing, the cache returns the stored summary without touching SWC.

**Package-level (the fast path).** For `node_modules`, the cache key is `SHA-256(package-name + version + resolved-dep-tree)`. If the lockfile says `react@19.1.0` and nothing in React's transitive dependency tree changed, every module in that package gets its summary from cache without reading a single source file from disk. At Teams scale, the majority of 50,000 modules are stable vendor packages. This tier means a new developer's first build is fast, because CI already seeded the remote cache.

## The parallel loop

Summarization is embarrassingly parallel. Every file is independent. No file's summary depends on any other file's summary. This is the actual loop:

```rust
paths
    .par_iter()
    .map(|path| {
        let source = fs::read_to_string(path)?;
        let hash = ContentHash::from_source(&source);

        // Cache hit: return stored summary, skip SWC entirely
        if let Some(cached) = cache.get(&hash)? {
            return Ok(BundleGraphNode {
                id: hash,
                path: path.to_string_lossy().into_owned(),
                summary: cached,
                alive: false,
                chunk_id: None,
                source: None,
            });
        }

        // Cache miss: parse with SWC, store summary
        let summarizer = ModuleSummarizer::new();
        let node = summarizer.summarize(path)?;
        cache.put(&node.id, &node.summary)?;
        Ok(node)
    })
    .collect()
```

`par_iter()` is [rayon](https://docs.rs/rayon/latest/rayon/). It distributes work across a thread pool with work-stealing. No shared mutable state. No locks. Each thread reads a file, hashes it, checks the cache, and either returns a stored summary or runs the SWC parse. The `AtomicUsize` counters for cache-hit tracking use `Ordering::Relaxed` because they're statistics, not synchronization.

On a warm rebuild where one file changed out of 10,000, there are 9,999 cache hits and 1 SWC parse. Each cache hit reads the source (for hashing), does a SHA-256, and looks up a 2KB blob from disk. That's it. No AST allocation, no visitor traversal, no memory pressure.

<div class="breakout">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 840 440" role="img" aria-label="Diagram: The Parallel Summarizer, showing rayon par_iter distributing files across threads with cache hit and miss paths">
  <rect width="840" height="440" fill="#F5F0E8" rx="4"/>
  <text x="420" y="32" text-anchor="middle" font-family="Georgia, serif" font-size="16" font-weight="bold" fill="#2B2421">The Parallel Summarizer</text>
  <rect x="310" y="52" width="220" height="40" rx="4" fill="#2B2421" stroke="none"/>
  <text x="420" y="77" text-anchor="middle" font-family="monospace" font-size="13" font-weight="bold" fill="#F5F0E8">paths.par_iter()</text>
  <line x1="340" y1="92" x2="120" y2="130" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <line x1="420" y1="92" x2="420" y2="130" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <line x1="500" y1="92" x2="720" y2="130" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <text x="210" y="122" font-family="Georgia, serif" font-size="10" fill="#2B2421">work-stealing</text>
  <text x="630" y="122" font-family="Georgia, serif" font-size="10" fill="#2B2421">work-stealing</text>
  <rect x="40" y="134" width="160" height="32" rx="4" fill="none" stroke="#2B2421" stroke-width="1.5"/>
  <text x="120" y="155" text-anchor="middle" font-family="monospace" font-size="11" fill="#2B2421">Thread 0</text>
  <rect x="340" y="134" width="160" height="32" rx="4" fill="none" stroke="#2B2421" stroke-width="1.5"/>
  <text x="420" y="155" text-anchor="middle" font-family="monospace" font-size="11" fill="#2B2421">Thread 1</text>
  <rect x="640" y="134" width="160" height="32" rx="4" fill="none" stroke="#2B2421" stroke-width="1.5"/>
  <text x="720" y="155" text-anchor="middle" font-family="monospace" font-size="11" fill="#2B2421">Thread N</text>
  <text x="558" y="155" text-anchor="middle" font-family="Georgia, serif" font-size="16" fill="#2B2421">...</text>
  <line x1="120" y1="166" x2="120" y2="194" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <line x1="420" y1="166" x2="420" y2="194" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <line x1="720" y1="166" x2="720" y2="194" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <rect x="40" y="196" width="160" height="40" rx="4" fill="none" stroke="#2B2421" stroke-width="1"/>
  <text x="120" y="213" text-anchor="middle" font-family="monospace" font-size="10" fill="#2B2421">read_to_string(path)</text>
  <text x="120" y="227" text-anchor="middle" font-family="monospace" font-size="10" fill="#2B2421">SHA-256(source)</text>
  <rect x="340" y="196" width="160" height="40" rx="4" fill="none" stroke="#2B2421" stroke-width="1"/>
  <text x="420" y="213" text-anchor="middle" font-family="monospace" font-size="10" fill="#2B2421">read_to_string(path)</text>
  <text x="420" y="227" text-anchor="middle" font-family="monospace" font-size="10" fill="#2B2421">SHA-256(source)</text>
  <rect x="640" y="196" width="160" height="40" rx="4" fill="none" stroke="#2B2421" stroke-width="1"/>
  <text x="720" y="213" text-anchor="middle" font-family="monospace" font-size="10" fill="#2B2421">read_to_string(path)</text>
  <text x="720" y="227" text-anchor="middle" font-family="monospace" font-size="10" fill="#2B2421">SHA-256(source)</text>
  <line x1="120" y1="236" x2="120" y2="262" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <line x1="420" y1="236" x2="420" y2="262" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <line x1="720" y1="236" x2="720" y2="262" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <rect x="40" y="264" width="160" height="28" rx="4" fill="none" stroke="#2B2421" stroke-width="1"/>
  <text x="120" y="283" text-anchor="middle" font-family="monospace" font-size="10" fill="#2B2421">cache.get(&amp;hash)?</text>
  <rect x="340" y="264" width="160" height="28" rx="4" fill="none" stroke="#2B2421" stroke-width="1"/>
  <text x="420" y="283" text-anchor="middle" font-family="monospace" font-size="10" fill="#2B2421">cache.get(&amp;hash)?</text>
  <rect x="640" y="264" width="160" height="28" rx="4" fill="none" stroke="#2B2421" stroke-width="1"/>
  <text x="720" y="283" text-anchor="middle" font-family="monospace" font-size="10" fill="#2B2421">cache.get(&amp;hash)?</text>
  <line x1="80" y1="292" x2="80" y2="320" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <line x1="160" y1="292" x2="160" y2="320" stroke="#A0522D" stroke-width="1.5" marker-end="url(#arrowR)"/>
  <line x1="380" y1="292" x2="380" y2="320" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <line x1="460" y1="292" x2="460" y2="320" stroke="#A0522D" stroke-width="1.5" marker-end="url(#arrowR)"/>
  <line x1="680" y1="292" x2="680" y2="320" stroke="#2B2421" stroke-width="1.5" marker-end="url(#arrow2)"/>
  <line x1="760" y1="292" x2="760" y2="320" stroke="#A0522D" stroke-width="1.5" marker-end="url(#arrowR)"/>
  <rect x="40" y="322" width="100" height="40" rx="4" fill="#2B2421" stroke="none"/>
  <text x="90" y="340" text-anchor="middle" font-family="monospace" font-size="10" font-weight="bold" fill="#F5F0E8">HIT</text>
  <text x="90" y="354" text-anchor="middle" font-family="monospace" font-size="9" fill="#F5F0E8">return cached</text>
  <rect x="148" y="322" width="100" height="40" rx="4" fill="#A0522D" stroke="none"/>
  <text x="198" y="340" text-anchor="middle" font-family="monospace" font-size="10" font-weight="bold" fill="#F5F0E8">MISS</text>
  <text x="198" y="354" text-anchor="middle" font-family="monospace" font-size="9" fill="#F5F0E8">SWC parse</text>
  <rect x="340" y="322" width="100" height="40" rx="4" fill="#2B2421" stroke="none"/>
  <text x="390" y="340" text-anchor="middle" font-family="monospace" font-size="10" font-weight="bold" fill="#F5F0E8">HIT</text>
  <text x="390" y="354" text-anchor="middle" font-family="monospace" font-size="9" fill="#F5F0E8">return cached</text>
  <rect x="448" y="322" width="100" height="40" rx="4" fill="#A0522D" stroke="none"/>
  <text x="498" y="340" text-anchor="middle" font-family="monospace" font-size="10" font-weight="bold" fill="#F5F0E8">MISS</text>
  <text x="498" y="354" text-anchor="middle" font-family="monospace" font-size="9" fill="#F5F0E8">SWC parse</text>
  <rect x="640" y="322" width="100" height="40" rx="4" fill="#2B2421" stroke="none"/>
  <text x="690" y="340" text-anchor="middle" font-family="monospace" font-size="10" font-weight="bold" fill="#F5F0E8">HIT</text>
  <text x="690" y="354" text-anchor="middle" font-family="monospace" font-size="9" fill="#F5F0E8">return cached</text>
  <rect x="748" y="322" width="100" height="40" rx="4" fill="#A0522D" stroke="none"/>
  <text x="798" y="340" text-anchor="middle" font-family="monospace" font-size="10" font-weight="bold" fill="#F5F0E8">MISS</text>
  <text x="798" y="354" text-anchor="middle" font-family="monospace" font-size="9" fill="#F5F0E8">SWC parse</text>
  <line x1="40" y1="384" x2="800" y2="384" stroke="#2B2421" stroke-width="0.5"/>
  <text x="420" y="406" text-anchor="middle" font-family="Georgia, serif" font-size="13" fill="#2B2421">Warm rebuild (1 file changed, 10k modules): 9,999 hits, 1 miss.</text>
  <text x="420" y="426" text-anchor="middle" font-family="Georgia, serif" font-size="13" font-weight="bold" fill="#A0522D">Zero shared mutable state. Zero locks. Zero coordination.</text>
  <defs>
    <marker id="arrow2" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto">
      <polygon points="0 0, 8 3, 0 6" fill="#2B2421"/>
    </marker>
    <marker id="arrowR" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto">
      <polygon points="0 0, 8 3, 0 6" fill="#A0522D"/>
    </marker>
  </defs>
</svg>
</div>

## The numbers

Measured on Apple Silicon (M-series), analysis pipeline only (SWC parse + cache + graph analysis, excluding the transform step):

| Modules | Cold (ms) | Warm (ms) | Speedup |
|--------:|----------:|----------:|--------:|
|     100 |        19 |         3 |    6.3x |
|     500 |        73 |        27 |    2.7x |
|   1,000 |       141 |        58 |    2.4x |
|   5,000 |       694 |       297 |    2.3x |
|  10,000 |     1,363 |       604 |    2.3x |

The warm build at 10,000 modules is 604ms. That's the time to hash 10,000 files, check 10,000 cache entries, SWC-parse the 1 file that changed, and rebuild the dependency graph.

The speedup looks like it converges at 2.3x, but that's misleading. The warm build is dominated by I/O: reading 10,000 files from disk to compute their hashes. The actual cache lookup and SWC parse for the single changed file is negligible. The bottleneck is `read_to_string` across 10,000 paths. With the package-level cache tier for `node_modules`, even those reads go away for vendor code, and the practical speedup on a repo where 40,000 of 50,000 modules are in `node_modules` is much higher.

At the large scale projection (50,000 modules), the analysis pipeline goes from 6.8 seconds cold to 604ms warm. That's an 11x speedup. Eleven times faster, and the warm build's cost is almost entirely reading files that didn't change.

## Why this matters for everything downstream

The compression ratio is not just a performance trick. It changes what's architecturally possible.

When your entire module graph fits in 100MB of summaries, Phase 2 (graph analysis, tree-shaking, chunk assignment) becomes a single-threaded scan at memory bandwidth. 100MB at memory-bus speed is about 50ms. The serial step that every other bundler treats as the bottleneck becomes a rounding error.

When summaries are content-addressed, they're safe to share across machines. CI summarizes once, developers pull from a remote cache, and a new developer's first build skips Phase 1 for everything CI already processed. The summary is the unit of caching, and it survives renames, moves, and copies because it's keyed to content, not path.

When the summarizer runs in parallel with zero shared state, it scales linearly with cores. Add cores, get proportionally faster. No Amdahl's law problem because there's no serial section.

The 50KB-to-2KB compression makes all of this fall out naturally. Shrink the representation, and the system that operates on it gets faster, cacheable, and parallelizable without any additional cleverness.