Commit 2118226
authored
[turbopack] Reduce the size of module graph datastructures (vercel#79706)
## Refactor module graph to reduce memory usage
### What?
This PR refactors the module graph implementation to reduce memory usage by:
1. Changing `graph_idx` from `usize` to `u32` to reduce memory footprint
2. Removing unused fields from `SingleModuleGraphModuleNode` (layer and issues)
3. Moving layer resolution to the point of use in dynamic imports and server actions
This is a small progression in runtime:

### Why?
These changes optimize memory usage in the module graph, which is particularly important for large applications. By removing unused fields and using more compact types, we can reduce the memory footprint of the graph.
Notably, SingleModuleGraphNode is now 24 bytes instead of 48. To make it smaller still we would need to reduce the size of visited moduel, perhaps by storing a reference to the graph that did the original visit? This would be tricky from a lifetimes perspective but much more optimal.1 parent 6e80e56 commit 2118226
3 files changed
Lines changed: 83 additions & 131 deletions
File tree
- crates/next-api/src
- turbopack/crates/turbopack-core/src/module_graph
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
435 | 435 | | |
436 | 436 | | |
437 | 437 | | |
438 | | - | |
439 | | - | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
440 | 443 | | |
441 | | - | |
442 | | - | |
| 444 | + | |
| 445 | + | |
443 | 446 | | |
444 | 447 | | |
445 | | - | |
| 448 | + | |
446 | 449 | | |
447 | 450 | | |
448 | 451 | | |
| |||
0 commit comments