[turbopack] Optimize the implementation of AutoMap/AutoSet #95694
Open
lukesandberg wants to merge 5 commits into
Open
[turbopack] Optimize the implementation of AutoMap/AutoSet
#95694lukesandberg wants to merge 5 commits into
lukesandberg wants to merge 5 commits into
Conversation
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Jul 10, 2026
Contributor
Stats from current PRWarning No stats were collected for Webpack because its stats job did not complete (it failed, was cancelled, or timed out). The results below only cover the bundlers that finished. ✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URLCommit: f7314ac |
Contributor
Tests PassedCommit: f7314ac |
…SmallVec The List variant of AutoMap used SmallVec<[(K,V); I]>, whose header is three usizes (length + heap pointer + capacity) even though AutoMap never lets the inner buffer spill on its own — it converts List -> Map before exceeding MAX_LIST_SIZE. The pointer/capacity words were dead weight and SmallVec's plain-usize length exposed no niche, so the AutoMap enum also paid for a separate discriminant word. As a result AutoSet/AutoMap were 32 bytes regardless of the inline-capacity const I. Replace it with InlineVec<T, I>: a bounded small-vec (still heap-spills up to MAX_LIST_SIZE, preserving today's spill semantics) with a two-byte header — len: NonZeroU8 (storing actual_len + 1) and cap: u8 — overlapping the inline array and heap pointer in a union. The NonZeroU8 niche lets the enclosing AutoMap enum fold its List/Map discriminant in for free. Sizes now shrink with I: AutoSet<TaskId, 0> 32 -> 16, AutoSet<TaskId, 3> 32 -> 24. Validated with unit tests (niche/size asserts + drop accounting) and clean under Miri with strict provenance.
c1fea49 to
f7314ac
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Optimize the implementation of AutoMap/AutoSet.
Previously the
Listvariant was backed by aSmallVecin inline mode, which needs at least 24 bytes of header (len,cap,ptr— allusize) even though the list never holds more than 32 elements.This replaces it with the
TinyVecstruct from turbo-tasks-backend which is now enhanced with support for aninlinearray. The length is aNonZeroU8, which reserves a niche theAutoMapenum folds its discriminant into — droppingAutoMap's minimum size to 16 bytes. This in turn shrinksTaskStorageand theLazyFieldenum. Some inline structs in TaskStorage are increased in size so we keep the 128 byte footprint