Skip to content

turbopack: gate ValueDebugFormat and ValueDebug behind debug_assertions#92628

Merged
sokra merged 3 commits intocanaryfrom
sokra/ValueDebugFormat-debug-only
Apr 15, 2026
Merged

turbopack: gate ValueDebugFormat and ValueDebug behind debug_assertions#92628
sokra merged 3 commits intocanaryfrom
sokra/ValueDebugFormat-debug-only

Conversation

@sokra
Copy link
Copy Markdown
Member

@sokra sokra commented Apr 10, 2026

What?

Gate ValueDebugFormat and ValueDebug behind #[cfg(debug_assertions)] across the turbopack crates, eliminating all debug formatting machinery from release binaries entirely.

Why?

ValueDebugFormat and ValueDebug contribute to release binary bloat. The field-level formatting logic (iterating struct fields, resolving Vcs, formatting collections recursively) and the per-type ValueDebug trait registrations are purely debugging aids with no value in production binaries.

Measured impact: -7.3 MiB (-5.5%) reduction in release libnext_napi_bindings.so binary size (from 126.26 MiB to 119.31 MiB).

How?

ValueDebug trait (debug/mod.rs):

  • In debug builds: full #[turbo_tasks::value_trait(no_debug)] with dbg() / dbg_depth() methods, ValueDebugFormatString, all blanket impls for collections/tuples/etc.
  • In release builds: empty marker trait with blanket impl<T: ?Sized> ValueDebug for T {}. This satisfies the supertrait bound on all value traits at zero cost — no per-type impl code is generated.

ValueDebugFormat trait (debug/mod.rs):

  • The value_debug_format method only exists under #[cfg(debug_assertions)]. In release builds, the trait is still present (for derive macros to reference) but has no methods.
  • All blanket impls (String, RcStr, Option, Vec, SmallVec, AutoSet, AutoMap, HashMap, FxIndexSet, FxIndexMap, tuples) are gated behind debug_assertions.
  • Supporting infrastructure (ValueDebugFormatString, PassthroughDebug, vdbg, internal submodule, value_debug_format_field) is compiled away.

Proc-macros:

  • #[derive(ValueDebugFormat)]: emits a full impl with value_debug_format method in debug builds, empty impl in release builds.
  • #[derive(ValueDebug)] and value_impl blocks: emit full debug impl in debug builds only — no release impl at all (the blanket marker trait impl covers it).
  • #[turbo_tasks::value]: transparent types get #[cfg(debug_assertions)] on the manual ValueDebug impl. Non-transparent types use #[cfg_attr(debug_assertions, derive(turbo_tasks::debug::internal::ValueDebug))] so the internal module is never referenced in release.
  • #[turbo_tasks::value_trait]: the Dynamic/Upcast/UpcastStrict impls for Box<dyn ValueDebug> are gated behind #[cfg(debug_assertions)].

Callers (vc/mod.rs, vc/resolved.rs, read_ref.rs, mapped_read_ref.rs, macro_helpers.rs, alias_map.rs):

  • All impl ValueDebugFormat blocks and their imports are gated behind #[cfg(debug_assertions)].

Verification

  • cargo check --release — clean (no errors, no warnings)
  • cargo clippy --all-targets — clean
  • CI passing

@nextjs-bot nextjs-bot added created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js. labels Apr 10, 2026
@nextjs-bot
Copy link
Copy Markdown
Contributor

nextjs-bot commented Apr 10, 2026

Tests Passed

@nextjs-bot
Copy link
Copy Markdown
Contributor

nextjs-bot commented Apr 10, 2026

Stats from current PR

🟢 1 improvement

Metric Canary PR Change Trend
node_modules Size 493 MB 492 MB 🟢 186 kB (0%) ██▄▄▄
📊 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 456ms █▁▁▁█
Cold (Ready in log) 440ms 440ms █▅▁▁▂
Cold (First Request) 818ms 821ms ▁████
Warm (Listen) 455ms 456ms █▅▅▅▅
Warm (Ready in log) 439ms 438ms ▃▅▃▄▆
Warm (First Request) 339ms 339ms ▂▅▇▆▅
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 456ms 456ms ▅▁▁▅▁
Cold (Ready in log) 440ms 441ms ▄▁▁▅█
Cold (First Request) 1.894s 1.897s ▄▂▄▅█
Warm (Listen) 456ms 455ms ▁█▁██
Warm (Ready in log) 439ms 440ms ▂▂▂▇█
Warm (First Request) 1.894s 1.918s █▄▇██

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 4.051s 4.036s █▃▃▁▃
Cached Build 4.060s 4.055s █▁▅▅▅
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 14.659s 14.643s ▁▃▄▆█
Cached Build 14.824s 14.746s ▁▂▂▄█
node_modules Size 493 MB 492 MB 🟢 186 kB (0%) ██▄▄▄
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
0_e7jpplzy-1d.js gzip 8.61 kB N/A -
0_pmftwo7hmuf.js gzip 158 B N/A -
02rwv4f_6c1sm.js gzip 8.55 kB N/A -
05go1o13ui4h8.js gzip 9.23 kB N/A -
08vhvpz7njgxl.js gzip 8.57 kB N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB
0d7tzhy6qxh_t.js gzip 49.1 kB N/A -
0g7jw_dt7_dey.js gzip 5.67 kB N/A -
0kcv7hz-0b8-q.js gzip 155 B N/A -
0n4ox_35s91v7.js gzip 8.5 kB N/A -
0t77rui7va2ul.js gzip 158 B N/A -
0vve0aeer3euy.js gzip 157 B N/A -
0wxpyd8r-vipl.js gzip 1.47 kB N/A -
1-g7xciuhb56_.js gzip 156 B N/A -
11q9_2xtrffzs.js gzip 10.1 kB N/A -
16lhqjoqbznyg.js gzip 220 B 220 B
1a3ew0_khbkhb.js gzip 157 B N/A -
1elt1qium-r2m.css gzip 115 B 115 B
1fjz2ak1ney0-.js gzip 154 B N/A -
1gk8qw910ozx1.js gzip 2.28 kB N/A -
1h4q0sv0fk24i.js gzip 8.55 kB N/A -
1ikr3081c4whe.js gzip 156 B N/A -
1jw65jwz-5bxm.js gzip 225 B N/A -
1mt43tko9mlgy.js gzip 9.8 kB N/A -
1t-5hgb4p0nld.js gzip 7.6 kB N/A -
1tffxp0fi80s8.js gzip 13.8 kB N/A -
1zxv27ew2zjrn.js gzip 8.58 kB N/A -
2__-e_ym8n788.js gzip 450 B N/A -
229ekdamwvswq.js gzip 157 B N/A -
23k74df7xvees.js gzip 8.59 kB N/A -
249774z9d3xpd.js gzip 168 B N/A -
2gdd25csjuru0.js gzip 13.3 kB N/A -
2iy12g5bci6dc.js gzip 12.9 kB N/A -
2j-s21vcbkac3.js gzip 154 B N/A -
2wfujv40rkljt.js gzip 13 kB N/A -
2yo2gbpw58jmk.js gzip 10.4 kB N/A -
36bdhi6x4fyla.js gzip 65.5 kB N/A -
3dfb2x6wi6mwz.js gzip 160 B N/A -
3gm9s9t5j8nwy.js gzip 8.5 kB N/A -
3gs_6b3llr-1t.js gzip 155 B N/A -
3qqu8mzx9_zwk.js gzip 70.8 kB N/A -
turbopack-0p.._xrn.js gzip 4.18 kB N/A -
turbopack-0y..l6me.js gzip 4.18 kB N/A -
turbopack-10.._ebb.js gzip 4.18 kB N/A -
turbopack-13..j7yv.js gzip 4.16 kB N/A -
turbopack-1o..-jrc.js gzip 4.18 kB N/A -
turbopack-1p..r2it.js gzip 4.17 kB N/A -
turbopack-1s..wvoi.js gzip 4.18 kB N/A -
turbopack-21..uewu.js gzip 4.18 kB N/A -
turbopack-21..064_.js gzip 4.18 kB N/A -
turbopack-2q..xb33.js gzip 4.18 kB N/A -
turbopack-32..xlq8.js gzip 4.18 kB N/A -
turbopack-37..4xjr.js gzip 4.19 kB N/A -
turbopack-3g..gkjl.js gzip 4.18 kB N/A -
turbopack-41..zbsm.js gzip 4.17 kB N/A -
06evto34q6kog.js gzip N/A 13 kB -
07djcf_vn6my1.js gzip N/A 153 B -
0aiow2efzggpv.js gzip N/A 8.59 kB -
0apirp-m3fna-.js gzip N/A 2.28 kB -
0auerozk6mrat.js gzip N/A 156 B -
0hneolwa4pot3.js gzip N/A 157 B -
0ht0kx4oat_0q.js gzip N/A 65.5 kB -
0ksot8co-qub9.js gzip N/A 7.6 kB -
0qu3po6qlx8a-.js gzip N/A 9.8 kB -
0wk9hd2b90qgx.js gzip N/A 155 B -
0xh2mn83oxr_r.js gzip N/A 155 B -
1_cu5qi_5umvo.js gzip N/A 160 B -
1-jqyfc89tixo.js gzip N/A 1.46 kB -
10ptfhou44vg-.js gzip N/A 8.55 kB -
15jd43m54o-sg.js gzip N/A 8.62 kB -
1ab2xruymo-oj.js gzip N/A 449 B -
1gf-rgtu3n2yt.js gzip N/A 154 B -
1iw767e5p8p9h.js gzip N/A 8.57 kB -
1k5ktx4fa8q6z.js gzip N/A 153 B -
1paexeze5sdue.js gzip N/A 13.8 kB -
1rjx6ckymkohg.js gzip N/A 8.51 kB -
1scs8sswn9jsh.js gzip N/A 8.55 kB -
1whaaa4yc-t-m.js gzip N/A 158 B -
26glj0tc2p9d7.js gzip N/A 154 B -
2qj5rro7dykxa.js gzip N/A 10.1 kB -
2rpp381qkur93.js gzip N/A 70.8 kB -
2ts1tavx8j3c1.js gzip N/A 12.9 kB -
2xc4caeel63ek.js gzip N/A 168 B -
3_i7z3jxw05k5.js gzip N/A 5.67 kB -
30qsbrhnphwel.js gzip N/A 225 B -
36pnnu0pdgtsd.js gzip N/A 13.3 kB -
3g1w9hlo9a4vy.js gzip N/A 157 B -
3iollk8wxspot.js gzip N/A 49.1 kB -
3xpwjrfb4nxc3.js gzip N/A 155 B -
4193narqgrim_.js gzip N/A 8.51 kB -
43jskxgkj3cju.js gzip N/A 9.23 kB -
43mmjowxr8jv8.js gzip N/A 8.58 kB -
444c-df85h-wn.js gzip N/A 10.4 kB -
turbopack-0o..2x4f.js gzip N/A 4.18 kB -
turbopack-0u..4odi.js gzip N/A 4.17 kB -
turbopack-19..2lxq.js gzip N/A 4.18 kB -
turbopack-1a..3sqx.js gzip N/A 4.16 kB -
turbopack-1i..crpw.js gzip N/A 4.18 kB -
turbopack-1k..ubyf.js gzip N/A 4.18 kB -
turbopack-1x..ahfl.js gzip N/A 4.17 kB -
turbopack-27..zoxr.js gzip N/A 4.18 kB -
turbopack-2s..4p6q.js gzip N/A 4.17 kB -
turbopack-3_..ojqg.js gzip N/A 4.18 kB -
turbopack-34..j7zj.js gzip N/A 4.18 kB -
turbopack-3f..cd82.js gzip N/A 4.17 kB -
turbopack-3m..96-f.js gzip N/A 4.19 kB -
turbopack-42..wbgs.js gzip N/A 4.18 kB -
Total 464 kB 464 kB ⚠️ +29 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 721 B 717 B
Total 721 B 717 B ✅ -4 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 428 B 436 B 🔴 +8 B (+2%)
Total 428 B 436 B ⚠️ +8 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.3 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 253 B 255 B
main-HASH.js gzip 39.4 kB 39.4 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.7 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 235 kB 235 kB ✅ -620 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 273 kB 272 kB
Total 399 kB 398 kB ✅ -635 B
Middleware
Canary PR Change
middleware-b..fest.js gzip 615 B 615 B
middleware-r..fest.js gzip 156 B 156 B
middleware.js gzip 44.1 kB 44.2 kB
edge-runtime..pack.js gzip 842 B 842 B
Total 45.7 kB 45.8 kB ⚠️ +54 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.37 MB 4.37 MB
index.pack gzip 113 kB 112 kB 🟢 1.76 kB (-2%)
index.pack.old gzip 114 kB 114 kB
Total 4.6 MB 4.6 MB ✅ -4.06 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 346 kB 346 kB
app-page-exp..prod.js gzip 192 kB 191 kB
app-page-tur...dev.js gzip 346 kB 345 kB
app-page-tur..prod.js gzip 191 kB 191 kB
app-page-tur...dev.js gzip 342 kB 342 kB
app-page-tur..prod.js gzip 189 kB 189 kB
app-page.run...dev.js gzip 342 kB 342 kB
app-page.run..prod.js gzip 190 kB 190 kB
app-route-ex...dev.js gzip 77 kB 76.9 kB
app-route-ex..prod.js gzip 52.5 kB 52.5 kB
app-route-tu...dev.js gzip 77 kB 77 kB
app-route-tu..prod.js gzip 52.5 kB 52.5 kB
app-route-tu...dev.js gzip 76.6 kB 76.6 kB
app-route-tu..prod.js gzip 52.2 kB 52.2 kB
app-route.ru...dev.js gzip 76.6 kB 76.5 kB
app-route.ru..prod.js gzip 52.2 kB 52.2 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.8 kB
pages-api.ru..prod.js gzip 33.4 kB 33.4 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.2 kB
pages.runtim..prod.js gzip 39 kB 39 kB
server.runti..prod.js gzip 62.9 kB 62.8 kB
Total 3.06 MB 3.06 MB ✅ -1.68 kB
📝 Changed Files (25 files)

Files with changes:

  • app-page-exp..ntime.dev.js
  • app-page-exp..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page.runtime.dev.js
  • app-page.runtime.prod.js
  • app-route-ex..ntime.dev.js
  • app-route-ex..time.prod.js
  • app-route-tu..ntime.dev.js
  • app-route-tu..time.prod.js
  • app-route-tu..ntime.dev.js
  • app-route-tu..time.prod.js
  • app-route.runtime.dev.js
  • app-route.ru..time.prod.js
  • pages-api-tu..ntime.dev.js
  • pages-api-tu..time.prod.js
  • pages-api.runtime.dev.js
  • pages-api.ru..time.prod.js
  • ... and 5 more
View diffs
app-page-exp..ntime.dev.js
failed to diff
app-page-exp..time.prod.js

Diff too large to display

app-page-tur..ntime.dev.js
failed to diff
app-page-tur..time.prod.js

Diff too large to display

app-page-tur..ntime.dev.js
failed to diff
app-page-tur..time.prod.js
failed to diff
app-page.runtime.dev.js
failed to diff
app-page.runtime.prod.js
failed to diff
app-route-ex..ntime.dev.js

Diff too large to display

app-route-ex..time.prod.js

Diff too large to display

app-route-tu..ntime.dev.js

Diff too large to display

app-route-tu..time.prod.js

Diff too large to display

app-route-tu..ntime.dev.js

Diff too large to display

app-route-tu..time.prod.js

Diff too large to display

app-route.runtime.dev.js

Diff too large to display

app-route.ru..time.prod.js

Diff too large to display

pages-api-tu..ntime.dev.js

Diff too large to display

pages-api-tu..time.prod.js

Diff too large to display

pages-api.runtime.dev.js

Diff too large to display

pages-api.ru..time.prod.js

Diff too large to display

pages-turbo...ntime.dev.js

Diff too large to display

pages-turbo...time.prod.js

Diff too large to display

pages.runtime.dev.js

Diff too large to display

pages.runtime.prod.js

Diff too large to display

server.runtime.prod.js

Diff too large to display

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

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 10, 2026

Merging this PR will degrade performance by 3.53%

❌ 1 regressed benchmark
✅ 16 untouched benchmarks
⏩ 3 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation packages-bundle.js[full] 987.2 ms 1,023.4 ms -3.53%

Comparing sokra/ValueDebugFormat-debug-only (6b385a4) with canary (fa60f50)

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.

The ValueDebugFormat trait method, ValueDebugFormatString enum, and all
related impl blocks (for Vc, ResolvedVc, ReadRef, MappedReadRef,
AliasMap, and all std/auto_hash_map/smallvec/FxIndex* types) are now
compiled only in debug builds. In release builds the derive macros emit
empty ValueDebugFormat impls (no method) and lightweight ValueDebug
impls that return the type name only, eliminating ~2.1% of binary size
from the formatting machinery.

Co-Authored-By: Claude <noreply@anthropic.com>
@sokra sokra force-pushed the sokra/ValueDebugFormat-debug-only branch from d16dabb to ba057ba Compare April 10, 2026 20:29
Comment thread turbopack/crates/turbo-tasks-macros/src/derive/value_debug_macro.rs Outdated
Comment thread turbopack/crates/turbo-tasks-macros/src/primitive_macro.rs Outdated
Comment thread turbopack/crates/turbo-tasks-macros/src/value_macro.rs Outdated
Comment thread turbopack/crates/turbo-tasks-macros/src/value_macro.rs Outdated
Instead of emitting a lightweight no-op ValueDebug impl for each type in
release builds, replace the value_trait definition itself with an empty
marker trait + blanket impl in release builds. This means no per-type
ValueDebug registration code is generated at all in release builds.

Co-Authored-By: Claude <noreply@anthropic.com>
@sokra sokra marked this pull request as ready for review April 13, 2026 07:37
@sokra sokra requested a review from lukesandberg April 13, 2026 07:38
Comment thread turbopack/crates/turbo-tasks/src/debug/mod.rs Outdated
Comment thread turbopack/crates/turbo-tasks/src/debug/mod.rs Outdated
- Move all `#[cfg(debug_assertions)]`-gated items into a single `detail`
  module so the gate is declared once instead of on every item
- Use `futures::future::BoxFuture` for the `Async` variant of
  `ValueDebugFormatString` instead of the verbose inline type

Co-Authored-By: Claude <noreply@anthropic.com>
@sokra sokra merged commit b56f155 into canary Apr 15, 2026
339 of 343 checks passed
@sokra sokra deleted the sokra/ValueDebugFormat-debug-only branch April 15, 2026 01:29
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants