Skip to content

[turbopack] Unify Cell Storage#92974

Merged
lukesandberg merged 9 commits intocanaryfrom
yes_but_dont
Apr 21, 2026
Merged

[turbopack] Unify Cell Storage#92974
lukesandberg merged 9 commits intocanaryfrom
yes_but_dont

Conversation

@lukesandberg
Copy link
Copy Markdown
Contributor

@lukesandberg lukesandberg commented Apr 18, 2026

What

Tightens the value-type persistence API and sets the table for a future eviction policy. Two user-visible changes on the #[turbo_tasks::value(...)] macro:

  • serialization = "none"serialization = "skip" — imperative ("skip persisting") instead of descriptive. Making it clear that it isn't that we are missing a feature but rather that we are choosing to not persist (of course persisting might be impossible but that is generally rare)
  • New evict = "always" | "last" | "never" attribute — replaces the old overloaded "none" semantic. Only valid with serialization = "skip". Defaults to "always".

Internally this collapses persistent_cell_data + transient_cell_data into one cell_data map and replaces the old bincode: Option<(enc, dec)> field with a four-variant ValueTypePersistence enum. Eviction machinery itself is a follow-up PR; this PR just gives each value type a precise, queryable persistence/eviction descriptor.

Why break out a new parameter?

serialization = "none" on canary conflated three different intents:

  1. Cheap recomputable outputs (SWC ASTs, codegen Ropes) — fine to evict, recompute is cheap.
  2. Expensive recomputable outputs (WASM modules, Node process pools) — re-derivable but costly.
  3. Session-scoped state (State<> cells, Arc<Mutex<_>> dedup histories) — can't be recomputed without losing accumulated mutations.

They all produced identical runtime behavior (stored in transient_cell_data), so eviction can't tell them apart. The fix is two orthogonal attributes:

// A cheap skip — default evict = "always"
#[turbo_tasks::value(serialization = "skip")]
// Expensive recompute — evict last under pressure
#[turbo_tasks::value(serialization = "skip", evict = "last")]
// Session-scoped state — never evict
#[turbo_tasks::value(serialization = "skip", evict = "never")]

The macro rejects evict on any other serialization mode.

ValueTypePersistence enum

Replaces ValueType.bincode: Option<(enc, dec)>:

pub enum ValueTypePersistence {
    Persistable(AnyEncodeFn, AnyDecodeFn<SharedReference>),  // auto, custom
    SkipPersist { expensive: bool },                         // skip (+ evict = last)
    HashOnly,                                                // hash
    SessionStateful,                                         // skip + evict = never
}

The existing "hash" mode gets its own HashOnly variant rather than being folded into SkipPersist, which lets the backend gate its hash-writing and hash-comparison paths precisely.

Unified cell_data storage

persistent_cell_data: AutoMap<CellId, TypedSharedReference> + transient_cell_data: AutoMap<CellId, SharedReference> collapse into cell_data: CellData. CellData is a newtype over AutoMap<CellId, SharedReference> with a custom bincode impl that filters non-Persistable entries at encode time. This removes the is_serializable_cell_content: bool parameter that was threading through ~14 read/write call sites.

Uses SharedReference instead of TypedSharedReferenceCellId already carries the ValueTypeId.

Annotation sweep

All prior serialization = "none" sites move to either serialization = "skip", evict = "never" or serialization = "skip", evict = "last" based on a per-site audit. Summary:

evict = "last" (6 sites) — re-derivable but expensive:

  • SwcPluginModule, EvaluatePool, ChildProcessPool, WorkerThreadPool, EffectInstance, Effects

evict = "never" (2 sites) — interior-mutable state accumulated across the session:

  • ConsoleUi (Arc<Mutex<SeenIssues>>), VersionState (State<VersionRef> with HMR invalidators)

The distinguishing rule: evict = "never" only when the value holds interior mutability accumulated across the session. Everything else can be re-derived (possibly expensively) by re-running the producing task.

Follow-ups (separate PRs)

Add new serializability options.  The key thing we want to distinguish is 'this cell is not serializable and it is important' vs this cell isn't _worth_ serializing

Currently there isn't a reason to distinguish, but with eviction there is.

In theory we should implement a priority system
* unevictable (e.g. DiskFileSystemInner). not serialiable fundamentally, evicting this breaks the watcher
* expensive (e.g. the WorkerThreadPool).  not serializable fundamentally, evicting this would be a perf hit
* cheaply derivable: (e.g. EcmascriptChunkItemContent).  serializable, but not worth it
* regular: everthing else

But for now there are just two levels  unevictable and everything else, if some of the 'everything else' isn't serializable that is fine.
@nextjs-bot nextjs-bot added created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js. labels Apr 18, 2026
Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 18, 2026

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing yes_but_dont (a23b6b4) with canary (6c6888a)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Comment thread turbopack/crates/turbo-tasks-backend/src/backend/storage_schema.rs Outdated
Comment thread turbopack/crates/turbo-tasks-backend/src/backend/storage_schema.rs Outdated
@nextjs-bot
Copy link
Copy Markdown
Contributor

Stats from current PR

✅ No significant changes detected

📊 All Metrics
📖 Metrics Glossary

Dev Server Metrics:

  • Listen = TCP port starts accepting connections
  • First Request = HTTP server returns successful response
  • Cold = Fresh build (no cache)
  • Warm = With cached build artifacts

Build Metrics:

  • Fresh = Clean build (no .next directory)
  • Cached = With existing .next directory

Change Thresholds:

  • Time: Changes < 50ms AND < 10%, OR < 2% are insignificant
  • Size: Changes < 1KB AND < 1% are insignificant
  • All other changes are flagged to catch regressions

⚡ Dev Server

Metric Canary PR Change Trend
Cold (Listen) 455ms 455ms ▅▅▅▅▁
Cold (Ready in log) 443ms 441ms ▅▅▆▆▅
Cold (First Request) 1.156s 1.101s ▁█▁█▁
Warm (Listen) 457ms 456ms ▅█▅█▅
Warm (Ready in log) 444ms 443ms ▁▄▁█▁
Warm (First Request) 350ms 352ms ▂▇▁█▁
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 455ms 455ms ▅▅▁▅█
Cold (Ready in log) 440ms 441ms ▃▅▁██
Cold (First Request) 1.889s 1.878s ▅█▆██
Warm (Listen) 455ms 455ms ▅▅▅▅▅
Warm (Ready in log) 441ms 440ms ▂▄▁▆▆
Warm (First Request) 1.891s 1.887s ▆█▆▇▇

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 3.926s 3.957s ▅▂█▄▄
Cached Build 3.988s 3.977s ▄▁█▁▃
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 14.588s 14.623s ▁▇▂█▆
Cached Build 14.737s 14.710s ▁▆▁█▇
node_modules Size 494 MB 494 MB ▇▇▁██
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
0_2mxpvrrod2f.js gzip 154 B N/A -
07rxhp_1_g4mu.js gzip 13.1 kB N/A -
08avva-dy02e7.js gzip 10.4 kB N/A -
09y82iy5lc0-z.js gzip 153 B N/A -
0bog1koyarlbh.js gzip 153 B N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB
0fli3_wppnim5.js gzip 12.9 kB N/A -
0k09jwjeb-tki.js gzip 13.8 kB N/A -
0kb7_ep3r1z0_.js gzip 10.1 kB N/A -
0kw8xgqdrilf6.js gzip 8.56 kB N/A -
0lgndkr1hands.js gzip 49.6 kB N/A -
0n2xjxbp1o-cf.js gzip 154 B N/A -
0ojkk2e654xsc.js gzip 8.59 kB N/A -
0tqzh3vdgxqs0.js gzip 155 B N/A -
0wxpyd8r-vipl.js gzip 1.47 kB N/A -
0xy2fhla48_rd.js gzip 9.24 kB N/A -
1-3n9-2yrca70.js gzip 156 B N/A -
10wqsvi2mgfmi.js gzip 9.82 kB N/A -
16lhqjoqbznyg.js gzip 220 B 220 B
16vepdkipri3r.js gzip 8.51 kB N/A -
17n96uu6y1pxq.js gzip 8.6 kB N/A -
18y4_8-9or0mn.js gzip 8.51 kB N/A -
1bzee7q1zyj1i.js gzip 169 B N/A -
1elt1qium-r2m.css gzip 115 B 115 B
1gq145j3kps-h.js gzip 8.62 kB N/A -
1nsh-mbn0e-se.js gzip 8.56 kB N/A -
1s-jybzia-ks5.js gzip 157 B N/A -
1tsrrp1tdngti.js gzip 13.3 kB N/A -
2__-e_ym8n788.js gzip 450 B N/A -
22o6xd9_ywdu6.js gzip 233 B N/A -
2is7z6q3dc_xy.js gzip 156 B N/A -
2kvj8yrfznmwx.js gzip 5.69 kB N/A -
2qv7m7xjnokgr.js gzip 8.58 kB N/A -
31gb7ha0076ao.js gzip 65.5 kB N/A -
342ijzvrpe53h.js gzip 2.29 kB N/A -
39rz5eajodm-i.js gzip 70.8 kB N/A -
3h-3_i35diwz_.js gzip 159 B N/A -
3qsufpzxbwkfg.js gzip 161 B N/A -
3tmsbs5k2j6h3.js gzip 155 B N/A -
3x0u96gydkgya.js gzip 154 B N/A -
44un3--wmqiyh.js gzip 7.61 kB N/A -
turbopack-0g..x5-a.js gzip 4.19 kB N/A -
turbopack-0j..k2mx.js gzip 4.19 kB N/A -
turbopack-0j..hh5a.js gzip 4.19 kB N/A -
turbopack-0r..9e-j.js gzip 4.19 kB N/A -
turbopack-0s..0s2z.js gzip 4.19 kB N/A -
turbopack-1b..3wfz.js gzip 4.19 kB N/A -
turbopack-23..fv87.js gzip 4.19 kB N/A -
turbopack-24.._76v.js gzip 4.19 kB N/A -
turbopack-2h..oi17.js gzip 4.17 kB N/A -
turbopack-2w..udhg.js gzip 4.19 kB N/A -
turbopack-3j.._sjy.js gzip 4.19 kB N/A -
turbopack-3k..tfg-.js gzip 4.19 kB N/A -
turbopack-43..qbh-.js gzip 4.2 kB N/A -
turbopack-43..70ze.js gzip 4.19 kB N/A -
02-ohkib1boio.js gzip N/A 155 B -
09t9i6o8nvir7.js gzip N/A 49.6 kB -
0arkbdqpxc37i.js gzip N/A 8.6 kB -
0bz-xifewa17d.js gzip N/A 8.63 kB -
0tvekitj587fh.js gzip N/A 8.51 kB -
0ug8gcgkteixz.js gzip N/A 154 B -
0yvk6-wi8e9wh.js gzip N/A 13.3 kB -
0z83a1om5rvtt.js gzip N/A 7.61 kB -
1-jqyfc89tixo.js gzip N/A 1.46 kB -
14t1kneseb8th.js gzip N/A 2.3 kB -
15sb1-dsqfk_j.js gzip N/A 8.59 kB -
1ab2xruymo-oj.js gzip N/A 449 B -
1dvuvo8jk3a6v.js gzip N/A 156 B -
1tu25qtsmfhar.js gzip N/A 9.82 kB -
1vein_gnv3mwr.js gzip N/A 8.56 kB -
1wzrm0xjjbzn5.js gzip N/A 10.1 kB -
1z3g0uaqtv9_3.js gzip N/A 8.56 kB -
2_2mij-bqvb21.js gzip N/A 157 B -
22w4zs_iimiwv.js gzip N/A 168 B -
23hbmknn7eyfs.js gzip N/A 155 B -
24gkrtv9a0_bk.js gzip N/A 160 B -
25a1yz7zua29z.js gzip N/A 13.8 kB -
26u4q6n2guyn5.js gzip N/A 154 B -
2bi5hx402juv-.js gzip N/A 8.58 kB -
2eleo8xxk7-8o.js gzip N/A 70.8 kB -
2hy56297fog9u.js gzip N/A 8.52 kB -
2m547nowcdwcx.js gzip N/A 157 B -
2oc_djlxina77.js gzip N/A 65.5 kB -
2ocku-vkz67rf.js gzip N/A 158 B -
2u_rpxq3tzytl.js gzip N/A 233 B -
311e8omf8_-ly.js gzip N/A 161 B -
368lim5wq0o0r.js gzip N/A 12.9 kB -
3d05m1jqni2og.js gzip N/A 157 B -
3drqjohogojbw.js gzip N/A 5.69 kB -
3g8l1m2-o-ewi.js gzip N/A 13.1 kB -
3jmkxsnxg0nrh.js gzip N/A 10.4 kB -
3wpp8nvyoj121.js gzip N/A 9.24 kB -
41o_vu8pnc-q8.js gzip N/A 153 B -
turbopack-06..gptw.js gzip N/A 4.19 kB -
turbopack-0f..4-x9.js gzip N/A 4.19 kB -
turbopack-0x..55ly.js gzip N/A 4.19 kB -
turbopack-0x..z2bu.js gzip N/A 4.19 kB -
turbopack-0z..f2r2.js gzip N/A 4.19 kB -
turbopack-1q..n6_k.js gzip N/A 4.19 kB -
turbopack-1t..fx3m.js gzip N/A 4.19 kB -
turbopack-22..aaoz.js gzip N/A 4.19 kB -
turbopack-2n..6mkj.js gzip N/A 4.19 kB -
turbopack-2u..8rul.js gzip N/A 4.17 kB -
turbopack-37..bmsx.js gzip N/A 4.19 kB -
turbopack-3h..ktv0.js gzip N/A 4.19 kB -
turbopack-3y..8yjt.js gzip N/A 4.2 kB -
turbopack-40..uisw.js gzip N/A 4.19 kB -
Total 465 kB 465 kB ⚠️ +57 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 717 B 718 B
Total 717 B 718 B ⚠️ +1 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 431 B 431 B
Total 431 B 431 B

📦 Webpack

Client

Main Bundles
Canary PR Change
2637-HASH.js gzip 4.63 kB N/A -
7724.HASH.js gzip 169 B N/A -
8274-HASH.js gzip 61.4 kB N/A -
8817-HASH.js gzip 5.59 kB N/A -
c3500254-HASH.js gzip 62.8 kB N/A -
framework-HASH.js gzip 59.7 kB 59.7 kB
main-app-HASH.js gzip 255 B 255 B
main-HASH.js gzip 39.4 kB 39.3 kB
webpack-HASH.js gzip 1.68 kB 1.68 kB
5887-HASH.js gzip N/A 5.61 kB -
6522-HASH.js gzip N/A 60.8 kB -
6779-HASH.js gzip N/A 4.63 kB -
8854.HASH.js gzip N/A 169 B -
eab920f9-HASH.js gzip N/A 62.8 kB -
Total 236 kB 235 kB ✅ -641 B
Polyfills
Canary PR Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Total 39.4 kB 39.4 kB
Pages
Canary PR Change
_app-HASH.js gzip 193 B 193 B
_error-HASH.js gzip 182 B 182 B
css-HASH.js gzip 333 B 334 B
dynamic-HASH.js gzip 1.81 kB 1.8 kB
edge-ssr-HASH.js gzip 255 B 255 B
head-HASH.js gzip 353 B 349 B 🟢 4 B (-1%)
hooks-HASH.js gzip 384 B 382 B
image-HASH.js gzip 581 B 581 B
index-HASH.js gzip 260 B 259 B
link-HASH.js gzip 2.51 kB 2.51 kB
routerDirect..HASH.js gzip 316 B 318 B
script-HASH.js gzip 386 B 386 B
withRouter-HASH.js gzip 313 B 314 B
1afbb74e6ecf..834.css gzip 106 B 106 B
Total 7.98 kB 7.97 kB ✅ -10 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 126 kB 126 kB
page.js gzip 274 kB 273 kB
Total 399 kB 399 kB ✅ -465 B
Middleware
Canary PR Change
middleware-b..fest.js gzip 617 B 617 B
middleware-r..fest.js gzip 156 B 156 B
middleware.js gzip 44 kB 44.4 kB
edge-runtime..pack.js gzip 842 B 842 B
Total 45.6 kB 46 kB ⚠️ +386 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 721 B 720 B
Total 721 B 720 B ✅ -1 B
Build Cache
Canary PR Change
0.pack gzip 4.38 MB 4.37 MB 🟢 6.56 kB (0%)
index.pack gzip 113 kB 113 kB
index.pack.old gzip 113 kB 114 kB
Total 4.61 MB 4.6 MB ✅ -5.17 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 347 kB 347 kB
app-page-exp..prod.js gzip 192 kB 192 kB
app-page-tur...dev.js gzip 347 kB 347 kB
app-page-tur..prod.js gzip 192 kB 192 kB
app-page-tur...dev.js gzip 343 kB 343 kB
app-page-tur..prod.js gzip 190 kB 190 kB
app-page.run...dev.js gzip 344 kB 344 kB
app-page.run..prod.js gzip 190 kB 190 kB
app-route-ex...dev.js gzip 77 kB 77 kB
app-route-ex..prod.js gzip 52.5 kB 52.5 kB
app-route-tu...dev.js gzip 77.1 kB 77.1 kB
app-route-tu..prod.js gzip 52.6 kB 52.6 kB
app-route-tu...dev.js gzip 76.7 kB 76.7 kB
app-route-tu..prod.js gzip 52.3 kB 52.3 kB
app-route.ru...dev.js gzip 76.6 kB 76.6 kB
app-route.ru..prod.js gzip 52.3 kB 52.3 kB
dist_client_...dev.js gzip 324 B 324 B
dist_client_...dev.js gzip 326 B 326 B
dist_client_...dev.js gzip 318 B 318 B
dist_client_...dev.js gzip 317 B 317 B
pages-api-tu...dev.js gzip 43.9 kB 43.9 kB
pages-api-tu..prod.js gzip 33.5 kB 33.5 kB
pages-api.ru...dev.js gzip 43.9 kB 43.9 kB
pages-api.ru..prod.js gzip 33.5 kB 33.5 kB
pages-turbo....dev.js gzip 53.3 kB 53.3 kB
pages-turbo...prod.js gzip 39.1 kB 39.1 kB
pages.runtim...dev.js gzip 53.3 kB 53.3 kB
pages.runtim..prod.js gzip 39.1 kB 39.1 kB
server.runti..prod.js gzip 63 kB 63 kB
Total 3.07 MB 3.07 MB ⚠️ +4 B
📝 Changed Files (2 files)

Files with changes:

  • pages-api.runtime.dev.js
  • pages.runtime.dev.js
View diffs
pages-api.runtime.dev.js

Diff too large to display

pages.runtime.dev.js

Diff too large to display

📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/cb5ab7df28a3431ab6b443a1778b1dfd15d06302/next

Comment thread turbopack/crates/turbo-tasks-backend/tests/derivable_cell.rs Outdated
@lukesandberg lukesandberg changed the title Unify Cell Storage [turbopack] Unify Cell Storage Apr 19, 2026
@lukesandberg lukesandberg marked this pull request as ready for review April 19, 2026 18:25
@lukesandberg lukesandberg requested a review from sokra April 19, 2026 18:25
Comment thread turbopack/crates/turbo-tasks-backend/src/backend/operation/update_cell.rs Outdated
@lukesandberg
Copy link
Copy Markdown
Contributor Author

Discussed with nicholas

lets split this into 2 keys

serialization="auto,hash,custom,none"
evict="always,never,last"

this will be a bit more intuitive but it does introduce the issue of having some 'meaningless combinations'

for now we can just ban unsupported combinations

@lukesandberg lukesandberg requested a review from sokra April 21, 2026 15:22
@lukesandberg lukesandberg merged commit d069c2e into canary Apr 21, 2026
489 of 497 checks passed
@lukesandberg lukesandberg deleted the yes_but_dont branch April 21, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants