Skip to content

Turboopack: put import attributes behind a pointer, 23% faster analyze#91347

Merged
mischnic merged 2 commits intocanaryfrom
mischnic/import-attribute-memory-layout
Mar 14, 2026
Merged

Turboopack: put import attributes behind a pointer, 23% faster analyze#91347
mischnic merged 2 commits intocanaryfrom
mischnic/import-attribute-memory-layout

Conversation

@mischnic
Copy link
Member

@mischnic mischnic commented Mar 13, 2026

The JS analyze microbenchmark got 23% faster:

Only a tiny fraction of imports have annotations, be it import ... with {...} or require(/*webpackIgnore: true*/...), so a Option<Pointer<Struct>> mkes sense here.

canary:
references/jsonwebtoken.js/full
                        time:   [63.250 ms 63.918 ms 64.752 ms]
                        change: [-5.2380% -3.0074% -0.8753%] (p = 0.01 < 0.05)
                        Change within noise threshold.
Found 12 outliers among 100 measurements (12.00%)
  5 (5.00%) high mild
  7 (7.00%) high severe


now:
references/jsonwebtoken.js/full
                        time:   [49.070 ms 49.166 ms 49.273 ms]
                        change: [-24.097% -23.079% -22.237%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe

This came up in #91278 (comment), which added another (tiny) field to ImportAttributes. But it caused a 6% regression in the microbenchmark anyway.

canary:
references/jsonwebtoken.js/full
                        time:   [63.250 ms 63.918 ms 64.752 ms]
                        change: [-5.2380% -3.0074% -0.8753%] (p = 0.01 < 0.05)
                        Change within noise threshold.
Found 12 outliers among 100 measurements (12.00%)
  5 (5.00%) high mild
  7 (7.00%) high severe

now:
references/jsonwebtoken.js/full
                        time:   [49.070 ms 49.166 ms 49.273 ms]
                        change: [-24.097% -23.079% -22.237%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe
@nextjs-bot nextjs-bot added created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js. labels Mar 13, 2026
Copy link
Member Author

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

@mischnic mischnic changed the title Turboopack: optimize analyzer memory layout, 23% faster Turboopack: optimize analyzer memory layout, 23% faster analyze Mar 13, 2026
@mischnic mischnic marked this pull request as ready for review March 13, 2026 23:13
@mischnic mischnic changed the title Turboopack: optimize analyzer memory layout, 23% faster analyze Turboopack: put attributes behind a pointer, 23% faster analyze Mar 13, 2026
@mischnic mischnic changed the title Turboopack: put attributes behind a pointer, 23% faster analyze Turboopack: put import attributes behind a pointer, 23% faster analyze Mar 13, 2026
@nextjs-bot
Copy link
Collaborator

nextjs-bot commented Mar 13, 2026

Tests Passed

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 13, 2026

Merging this PR will improve performance by 25.6%

⚡ 15 improved benchmarks
✅ 2 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation build[mui] 2.9 s 2.8 s +3.16%
Simulation build[lucide-react-single] 990.5 ms 924.3 ms +7.16%
Simulation build[framer-motion-single] 2.1 s 2 s +3.91%
Simulation build[date-fns-all] 2 s 2 s +3.78%
Simulation build[framer-motion-all] 2.7 s 2.6 s +3.56%
Simulation build[joy] 2 s 1.9 s +3.76%
Simulation build[date-fns-single] 1.4 s 1.3 s +5.73%
Simulation react-dom-client.development.js[tracing] 449.7 ms 374.1 ms +20.19%
Simulation packages-bundle.js[full] 1.2 s 1 s +16.29%
Simulation jsonwebtoken.js[tracing] 332.8 ms 264.9 ms +25.6%
Simulation app-page-turbo.runtime.prod.js[tracing] 672.9 ms 579.2 ms +16.18%
Simulation react-dom-client.development.js[full] 516.9 ms 434 ms +19.1%
Simulation packages-bundle.js[tracing] 1,011.7 ms 872.9 ms +15.89%
Simulation app-page-turbo.runtime.prod.js[full] 791.7 ms 681.1 ms +16.23%
Simulation jsonwebtoken.js[full] 380.4 ms 304.2 ms +25.06%

Comparing mischnic/import-attribute-memory-layout (d1f745a) with canary (cd49df2)

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.

@nextjs-bot
Copy link
Collaborator

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) 559ms 608ms ▁▁▁█▁
Cold (Ready in log) 552ms 567ms ▁▁▁█▁
Cold (First Request) 1.247s 1.228s ▃▁▃█▁
Warm (Listen) 559ms 560ms ▁▁▁█▁
Warm (Ready in log) 556ms 558ms ▁▁▁█▁
Warm (First Request) 455ms 465ms ▁▁▁█▁
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 456ms 455ms ▁▁▁▁▁
Cold (Ready in log) 438ms 437ms ▁▂▂▂▂
Cold (First Request) 1.957s 1.947s ▂▁▁▁▂
Warm (Listen) 455ms 456ms ▁▁▁▁▁
Warm (Ready in log) 437ms 437ms ▂▃▂▂▃
Warm (First Request) 1.955s 1.932s ▂▁▁▁▂

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 5.377s 5.326s ▁▂▁█▂
Cached Build 5.362s 5.401s ▁▂▁█▁
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 14.312s 14.294s ▃▁▁▁▁
Cached Build 14.399s 14.388s ▃▁▁▁▁
node_modules Size 482 MB 482 MB ▁▁▁▁▁
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles: **408 kB** → **408 kB** ✅ -19 B

80 files with content-based hashes (individual files not comparable between builds)

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 762 B 759 B
Total 762 B 759 B ✅ -3 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 450 B 451 B
Total 450 B 451 B ⚠️ +1 B

📦 Webpack

Client

Main Bundles
Canary PR Change
5528-HASH.js gzip 5.54 kB N/A -
6280-HASH.js gzip 59.9 kB N/A -
6335.HASH.js gzip 169 B N/A -
912-HASH.js gzip 4.59 kB N/A -
e8aec2e4-HASH.js gzip 62.7 kB N/A -
framework-HASH.js gzip 59.7 kB 59.7 kB
main-app-HASH.js gzip 256 B 254 B
main-HASH.js gzip 39.2 kB 39.2 kB
webpack-HASH.js gzip 1.68 kB 1.68 kB
262-HASH.js gzip N/A 4.59 kB -
2889.HASH.js gzip N/A 169 B -
5602-HASH.js gzip N/A 5.55 kB -
6948ada0-HASH.js gzip N/A 62.7 kB -
9544-HASH.js gzip N/A 60.6 kB -
Total 234 kB 235 kB ⚠️ +721 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 194 B 194 B
_error-HASH.js gzip 183 B 180 B 🟢 3 B (-2%)
css-HASH.js gzip 331 B 330 B
dynamic-HASH.js gzip 1.81 kB 1.81 kB
edge-ssr-HASH.js gzip 256 B 256 B
head-HASH.js gzip 351 B 352 B
hooks-HASH.js gzip 384 B 383 B
image-HASH.js gzip 580 B 581 B
index-HASH.js gzip 260 B 260 B
link-HASH.js gzip 2.51 kB 2.51 kB
routerDirect..HASH.js gzip 320 B 319 B
script-HASH.js gzip 386 B 386 B
withRouter-HASH.js gzip 315 B 315 B
1afbb74e6ecf..834.css gzip 106 B 106 B
Total 7.98 kB 7.98 kB ✅ -1 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 125 kB 125 kB
page.js gzip 267 kB 267 kB
Total 392 kB 392 kB ✅ -268 B
Middleware
Canary PR Change
middleware-b..fest.js gzip 615 B 614 B
middleware-r..fest.js gzip 156 B 155 B
middleware.js gzip 43.6 kB 43.9 kB
edge-runtime..pack.js gzip 842 B 842 B
Total 45.2 kB 45.5 kB ⚠️ +326 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 715 B 718 B
Total 715 B 718 B ⚠️ +3 B
Build Cache
Canary PR Change
0.pack gzip 4.24 MB 4.23 MB 🟢 9.46 kB (0%)
index.pack gzip 109 kB 108 kB
index.pack.old gzip 108 kB 108 kB
Total 4.46 MB 4.44 MB ✅ -10.9 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 332 kB 332 kB
app-page-exp..prod.js gzip 180 kB 180 kB
app-page-tur...dev.js gzip 332 kB 332 kB
app-page-tur..prod.js gzip 180 kB 180 kB
app-page-tur...dev.js gzip 328 kB 328 kB
app-page-tur..prod.js gzip 178 kB 178 kB
app-page.run...dev.js gzip 329 kB 329 kB
app-page.run..prod.js gzip 178 kB 178 kB
app-route-ex...dev.js gzip 76 kB 76 kB
app-route-ex..prod.js gzip 51.7 kB 51.7 kB
app-route-tu...dev.js gzip 76 kB 76 kB
app-route-tu..prod.js gzip 51.7 kB 51.7 kB
app-route-tu...dev.js gzip 75.6 kB 75.6 kB
app-route-tu..prod.js gzip 51.5 kB 51.5 kB
app-route.ru...dev.js gzip 75.5 kB 75.5 kB
app-route.ru..prod.js gzip 51.4 kB 51.4 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.3 kB 43.3 kB
pages-api-tu..prod.js gzip 33 kB 33 kB
pages-api.ru...dev.js gzip 43.3 kB 43.3 kB
pages-api.ru..prod.js gzip 33 kB 33 kB
pages-turbo....dev.js gzip 52.7 kB 52.7 kB
pages-turbo...prod.js gzip 38.6 kB 38.6 kB
pages.runtim...dev.js gzip 52.7 kB 52.7 kB
pages.runtim..prod.js gzip 38.6 kB 38.6 kB
server.runti..prod.js gzip 62.4 kB 62.4 kB
Total 2.95 MB 2.95 MB ⚠️ +1 B
📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/c15daf37eeaa08161f3b34d57ad862bf79c4deda/next

r.issue_source
.unwrap_or_else(|| IssueSource::from_source_only(source)),
r.annotations.clone(),
r.annotations.as_ref().map(|a| (**a).clone()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't a simple clone work here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does the Option<Arc<ImportAttributes>> to Option<ImportAttributes> conversion

pub module_path: Wtf8Atom,
pub imported_symbol: ImportedSymbol,
pub annotations: ImportAnnotations,
pub annotations: Option<Arc<ImportAnnotations>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a Box instead of Arc be better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arc:

references/jsonwebtoken.js/full
                        time:   [47.028 ms 47.163 ms 47.306 ms]
                        change: [-2.4739% -1.5284% -0.6681%] (p = 0.00 < 0.05)
                        Change within noise threshold.

Box:

references/jsonwebtoken.js/full
                        time:   [48.934 ms 49.123 ms 49.358 ms]
                        change: [+3.6630% +4.1558% +4.7521%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 11 outliers among 100 measurements (11.00%)
  8 (8.00%) high mild
  3 (3.00%) high severe

@mischnic mischnic merged commit baad064 into canary Mar 14, 2026
289 of 295 checks passed
Copy link
Member Author

Merge activity

@mischnic mischnic deleted the mischnic/import-attribute-memory-layout branch March 14, 2026 10:17
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.

4 participants