Skip to content

perf: reuse SWC parser allocator during make#14795

Draft
hardfist wants to merge 1 commit into
mainfrom
perf/reuse-swc-allocator
Draft

perf: reuse SWC parser allocator during make#14795
hardfist wants to merge 1 commit into
mainfrom
perf/reuse-swc-allocator

Conversation

@hardfist

Copy link
Copy Markdown
Contributor

Summary

  • reuse one SWC expression allocator arena per make worker instead of creating a new arena for every JavaScript module parse
  • reset the arena after each parse while retaining its backing memory for the next module
  • keep allocator reuse thread-local so parallel module builds do not share mutable arena state
  • cover the reset-and-reuse behavior with a focused unit test

JavaScript module parsing runs once per module during make, so repeated allocator setup and backing-buffer allocation scale with module count. Retaining the arena per worker removes that repeated allocation churn while preserving the existing AST lifetime boundary: all arena-backed values are consumed before the guard resets the allocator.

The guard also resets and returns the arena on early error returns. Reentrant parsing can temporarily create another allocator, but only one arena is retained per worker, preventing the cache from growing without bound.

Expected impact: fewer system allocations and frees in the make-stage JavaScript parser hot path, especially for compilations with many modules.

Related links

N/A

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 8c9417a to fix(rsc): preserve multiple referenced client exports (#14794) by Cong-Cong Pan

❌ Size increased by 4.00KB from 66.55MB to 66.56MB (⬆️0.01%)

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

📝 Benchmark detail: Open

Name Base (27ff319) Current Change
10000_big_production-mode_disable-minimize + exec 12.1 s ± 343 ms 12 s ± 265 ms -1.02 %
10000_development-mode + exec 904 ms ± 44 ms 889 ms ± 28 ms -1.70 %
10000_development-mode_hmr + stats 158 ms ± 8.8 ms 156 ms ± 4.1 ms -1.07 %
10000_development-mode_noop-loader + exec 1.74 s ± 31 ms 1.74 s ± 29 ms -0.21 %
10000_production-mode + exec 1.02 s ± 30 ms 1.03 s ± 34 ms +0.74 %
10000_production-mode_persistent-cold + exec 1.19 s ± 36 ms 1.19 s ± 39 ms -0.22 %
10000_production-mode_persistent-hot + exec 637 ms ± 14 ms 635 ms ± 19 ms -0.44 %
10000_production-mode_source-map + exec 1.19 s ± 15 ms 1.18 s ± 31 ms -0.29 %
arco-pro_development-mode + exec 1.34 s ± 48 ms 1.27 s ± 84 ms -4.91 %
arco-pro_development-mode_hmr + stats 33 ms ± 0.39 ms 33 ms ± 0.49 ms -0.88 %
arco-pro_production-mode + exec 2.35 s ± 127 ms 2.29 s ± 57 ms -2.50 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 2.38 s ± 37 ms 2.4 s ± 113 ms +0.91 %
arco-pro_production-mode_persistent-cold + exec 2.39 s ± 108 ms 2.4 s ± 111 ms +0.22 %
arco-pro_production-mode_persistent-hot + exec 344 ms ± 3.4 ms 342 ms ± 6.4 ms -0.64 %
arco-pro_production-mode_source-map + exec 2.8 s ± 163 ms 2.81 s ± 84 ms +0.29 %
arco-pro_production-mode_source-map_persistent-cold + exec 2.91 s ± 102 ms 2.88 s ± 98 ms -1.06 %
arco-pro_production-mode_source-map_persistent-hot + exec 481 ms ± 13 ms 474 ms ± 8.9 ms -1.41 %
arco-pro_production-mode_traverse-chunk-modules + exec 2.36 s ± 144 ms 2.36 s ± 50 ms +0.11 %
bundled-threejs_development-mode + exec 179 ms ± 6.5 ms 180 ms ± 2.7 ms +0.56 %
bundled-threejs_production-mode + exec 209 ms ± 5.1 ms 211 ms ± 7.6 ms +1.34 %
large-dyn-imports_development-mode + exec 1.19 s ± 30 ms 1.17 s ± 37 ms -1.01 %
large-dyn-imports_production-mode + exec 1.28 s ± 46 ms 1.27 s ± 61 ms -0.33 %
threejs_development-mode_10x + exec 761 ms ± 13 ms 771 ms ± 24 ms +1.29 %
threejs_development-mode_10x_hmr + stats 109 ms ± 5.9 ms 112 ms ± 15 ms +2.87 %
threejs_production-mode_10x + exec 2.83 s ± 21 ms 2.81 s ± 49 ms -0.64 %
threejs_production-mode_10x_persistent-cold + exec 2.95 s ± 21 ms 2.95 s ± 118 ms -0.11 %
threejs_production-mode_10x_persistent-hot + exec 401 ms ± 89 ms 379 ms ± 4.6 ms -5.63 %
threejs_production-mode_10x_source-map + exec 3.67 s ± 194 ms 3.61 s ± 33 ms -1.54 %
10000_big_production-mode_disable-minimize + rss memory 2209 MiB ± 29.7 MiB 1873 MiB ± 49.5 MiB -15.22 %
10000_development-mode + rss memory 551 MiB ± 12.5 MiB 544 MiB ± 5.12 MiB -1.15 %
10000_development-mode_hmr + rss memory 788 MiB ± 37.5 MiB 773 MiB ± 30.3 MiB -1.99 %
10000_development-mode_noop-loader + rss memory 816 MiB ± 9.19 MiB 806 MiB ± 6.47 MiB -1.19 %
10000_production-mode + rss memory 473 MiB ± 12.2 MiB 467 MiB ± 8.54 MiB -1.37 %
10000_production-mode_persistent-cold + rss memory 669 MiB ± 3.78 MiB 662 MiB ± 6.34 MiB -1.11 %
10000_production-mode_persistent-hot + rss memory 662 MiB ± 40.2 MiB 662 MiB ± 29.3 MiB -0.09 %
10000_production-mode_source-map + rss memory 485 MiB ± 7.03 MiB 477 MiB ± 9.11 MiB -1.69 %
arco-pro_development-mode + rss memory 407 MiB ± 5.41 MiB 440 MiB ± 9.42 MiB +8.20 %
arco-pro_development-mode_hmr + rss memory 435 MiB ± 8.79 MiB 465 MiB ± 19.3 MiB +6.93 %
arco-pro_production-mode + rss memory 582 MiB ± 7.9 MiB 611 MiB ± 26.4 MiB +5.02 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 599 MiB ± 9.59 MiB 622 MiB ± 47.1 MiB +3.77 %
arco-pro_production-mode_persistent-cold + rss memory 666 MiB ± 37.4 MiB 704 MiB ± 17.4 MiB +5.75 %
arco-pro_production-mode_persistent-hot + rss memory 296 MiB ± 11.2 MiB 294 MiB ± 9.13 MiB -0.65 %
arco-pro_production-mode_source-map + rss memory 687 MiB ± 11.1 MiB 726 MiB ± 22.1 MiB +5.71 %
arco-pro_production-mode_source-map_persistent-cold + rss memory 817 MiB ± 20.8 MiB 858 MiB ± 18.7 MiB +5.00 %
arco-pro_production-mode_source-map_persistent-hot + rss memory 425 MiB ± 21.9 MiB 423 MiB ± 22.2 MiB -0.58 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 588 MiB ± 9.35 MiB 615 MiB ± 36.1 MiB +4.56 %
bundled-threejs_development-mode + rss memory 134 MiB ± 7.73 MiB 128 MiB ± 3.7 MiB -5.00 %
bundled-threejs_production-mode + rss memory 145 MiB ± 9.85 MiB 144 MiB ± 7.75 MiB -0.50 %
large-dyn-imports_development-mode + rss memory 559 MiB ± 8.02 MiB 554 MiB ± 6.49 MiB -0.98 %
large-dyn-imports_production-mode + rss memory 409 MiB ± 4.47 MiB 410 MiB ± 2.31 MiB +0.19 %
threejs_development-mode_10x + rss memory 439 MiB ± 16.8 MiB 437 MiB ± 6.83 MiB -0.42 %
threejs_development-mode_10x_hmr + rss memory 614 MiB ± 26.6 MiB 603 MiB ± 21.2 MiB -1.84 %
threejs_production-mode_10x + rss memory 621 MiB ± 17.5 MiB 615 MiB ± 10.7 MiB -1.01 %
threejs_production-mode_10x_persistent-cold + rss memory 575 MiB ± 6.9 MiB 576 MiB ± 10.6 MiB +0.17 %
threejs_production-mode_10x_persistent-hot + rss memory 379 MiB ± 12.7 MiB 380 MiB ± 9.13 MiB +0.33 %
threejs_production-mode_10x_source-map + rss memory 745 MiB ± 20 MiB 745 MiB ± 16 MiB -0.09 %

Base persistent cache hit rate: 👍

Current persistent cache hit rate: 👍

@codspeed-hq

codspeed-hq Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 41 untouched benchmarks
⏩ 47 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation rust@create_chunk_assets 1.4 ms 1.5 ms -2.99%
Simulation rust@create_module_hashes 8.5 ms 8.3 ms +2.33%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/reuse-swc-allocator (8c9417a) with main (786dec5)

Open in CodSpeed

Footnotes

  1. 47 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant