Skip to content

perf(build): cold -b of many small projects in 26% less time and 6% less memory - #1083

Merged
maschwenk merged 4 commits into
mainfrom
perf/build-shared-files-large-slabs
Nov 24, 2026
Merged

maschwenk merged 4 commits into
mainfrom
perf/build-shared-files-large-slabs

Conversation

@maschwenk

Copy link
Copy Markdown
Collaborator

a cold tsrs -b over thousands of small composite projects held on to memory from projects it had already built, and spent much of its time handing small loader rounds to the worker pool all builders share. each declaration or JSON file shared across the build got a Region::new on whatever thread parsed it, in the same standard slabs as the program loading it, so every kept file pinned a 1 MiB slab of a freed program. every round of two or more files also went to the one worker_pool(), though under -b most rounds are a few files

the fix is Christian Vuerings's, from christianvuerings#13. shared files now take their registered regions from the thread's large slabs (Region::new_in_large_slabs), and with more than one builder a loader round of fewer than 128 files is parsed on the builder thread, as --singleThreaded already parses every round. a non-watch -p build reaches neither path; watch sessions get the slab change too

the #1075 repro (21,000 projects, --typeChain=5), release builds of main (7a04074) and this branch alternating on one c8g.48xlarge (192 vCPU), medians after a warmup run each, changes as the median per-pair ratio:

-b --builders 32 --checkers 1, 10 pairs main this branch change
wall 25.5 s 18.9 s βˆ’26%
CPU 1,044 s 794 s βˆ’24%
peak RSS 14.2 GiB 13.3 GiB βˆ’6.5%
instructions (3 pairs) 4,502 G 4,174 G βˆ’7.4%

at the default -b (4 builders, 4 checkers, 3 pairs): wall 170.6 s to 126.2 s (βˆ’27%), CPU 4,061 s to 1,687 s (βˆ’58%), peak RSS 30.0 GiB to 29.1 GiB (βˆ’3%). -b --singleThreaded on 2,000 projects of the same generator (2 pairs): instructions and wall unchanged, peak RSS 1,680 MiB to 1,338 MiB (βˆ’20%)

the slab change alone gives the memory win (βˆ’6.5% peak RSS; time and instructions within noise over 5 pairs), and the parse rounds give the time win. wall and CPU come from runs without perf stat, which slows main's pool handoffs far more than this branch's

the 189,000 emitted .d.ts, .d.ts.map and .tsbuildinfo files and stdout are byte-identical to main's. the diff adds no unsafe and leaves the tools/lint/source.mjs inventories unchanged: a registered region in large slabs only combines two flags Region::new_in already takes independently. the new arena test runs in a child process through a copy of the isolated helper the other crates' RSS tests use

Fixes #1075

Co-authored-by: Christian Vuerings 127199+christianvuerings@users.noreply.github.com

christianvuerings and others added 4 commits November 24, 2026 11:22
…programs

A build keeps every declaration and JSON file its projects share for the whole build (FileRegions), in a region carved
from the same per-thread standard slabs as the short-lived regions of the program that parsed it. A slab goes back only
when all of its chunks are freed, so one such file keeps a slab resident after its program is freed, and the build's
memory grows with every project. Carve those regions from the thread's large slabs instead
(Region::new_in_large_slabs), so finished programs give their slabs back.
…ilders share the pool

Each project's file loader sends every round of two or more files to the worker pool that all builders of a tsc -b
share. Under -b most rounds are a few files, because the shared declaration files are already parsed, and handing each
round to the pool costs more than parsing it. ProgramOptions::min_parallel_round_files sets the smallest round the pool
gets (default 2, as before); the build sets 128 when more than one builder runs.
…ted helper

tsrs_core gets the isolated module that the tsrs_cli, tsrs_api, tsrs_fswatch and tsrs_incremental tests use
(AGENTS.md: a test that measures RSS runs alone in a child process), in place of a copy inside arena_test.rs.
@maschwenk
maschwenk enabled auto-merge November 24, 2026 16:23
@maschwenk
maschwenk added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 0487a46 Nov 24, 2026
69 checks passed
@maschwenk
maschwenk deleted the perf/build-shared-files-large-slabs branch November 24, 2026 16:35
@codspeed

codspeed Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

βœ… 8 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing perf/build-shared-files-large-slabs (0957891) with main (fce7f32)

Open in CodSpeed

Footnotes

  1. 8 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. ↩

@github-actions

Copy link
Copy Markdown
Contributor

Performance change vs main

Workflow run Β· main fce7f32a1e1e β†’ PR merge 373dbec15753 (head 09578915d8ea)

Clef gate: Clef estimated 80.3% default and single-threaded wall time, 85.3% peak RSS, 73.0% single-threaded instruction count impact probability.

Release builds in fast mode (TSRS_FAST=1) with Hyperfine 2 hardware counters. After warming each binary, alternating main/PR pairs measure wall time at both the fast preset's default checker count and with --singleThreaded, with ten pairs per configuration by default. Instructions come from the single-threaded runs; peak RSS comes from the default-count runs.
Incremental runs start with fresh build info before every invocation; check runs disable incremental compilation.

Project Mode Single-thread wall time Ξ” Single-thread instructions Ξ” Default wall time Ξ” Default peak RSS Ξ”
vscode check +4.6% -0.001% +1.6% +0.1%
vscode incremental +1.2% +0.001% -1.3% -0.1%
xstate-main check -3.3% +0.001% +3.9% +0.1%
xstate-main incremental +0.1% 0.000% +0.3% -0.4%
webpack check +0.2% -0.001% +1.0% 0.0%
webpack incremental -1.7% -0.001% +0.9% -0.4%
mui-docs check -3.6% +0.024% -0.5% -0.2%
mui-docs incremental +0.5% -0.019% -0.3% 0.0%
Compiler check +3.8% 0.000% -0.9% -0.9%
Compiler incremental -7.8% +0.001% +0.2% -0.1%
Compiler-Unions check +0.7% 0.000% -5.9% +0.2%
Compiler-Unions incremental -0.8% -0.002% -2.2% -0.2%
cal-diy check -3.1% -0.001% +0.7% +0.1%
cal-diy incremental 0.0% -0.007% -0.9% 0.0%
formbricks-web check -1.7% +0.001% -0.5% -0.2%
formbricks-web incremental -1.2% -0.005% +0.2% -0.1%
supabase-studio check -0.9% 0.000% +0.1% +0.2%
supabase-studio incremental +1.8% -0.002% -0.3% -0.2%
t3code-server check -4.0% -0.003% +0.3% +0.7%
t3code-server incremental -2.2% +0.006% -1.9% 0.0%
mikro-orm check +0.4% -0.001% +1.4% +0.2%
mikro-orm incremental +0.5% +0.002% -2.6% +0.2%
next-packages-next check -1.6% 0.000% +2.9% +0.6%
next-packages-next incremental +1.0% 0.000% +10.5% +0.1%
next-root check +1.7% 0.000% -0.2% +0.1%
next-root incremental -1.3% -0.001% -1.0% -0.4%
storybook check +2.5% +0.001% +0.4% +0.3%
storybook incremental +0.3% +0.005% -1.8% +0.3%
nuxt check -0.9% +0.001% 0.0% +0.2%
nuxt incremental +0.8% +0.005% -1.3% +0.4%
playwright check +0.3% +0.001% -3.0% +1.2%
playwright incremental +1.2% -0.002% +7.2% +0.3%
drizzle-orm check -3.9% -0.004% +0.9% -1.0%
drizzle-orm incremental -2.6% 0.000% -1.1% -0.3%
typeorm check +6.2% +0.002% +2.8% +0.3%
typeorm incremental -0.7% -0.002% -0.2% +0.3%
date-fns check +0.1% -0.010% -0.7% +0.1%
date-fns incremental 0.0% +0.011% -2.0% +0.3%

Negative means the PR used less; positive means it used more. Deltas are medians of paired PR/main ratios for wall time and instructions. Single-threaded runs reduce scheduling noise; shared CI machines can still add noise to wall time.

Measured medians (main β†’ PR)
Project Mode Single-thread wall time (s) Single-thread instructions Default wall time (s) Default peak RSS (MiB)
vscode check 11.219 β†’ 14.244 82,266,713,428 β†’ 82,265,922,111.5 3.156 β†’ 3.197 1838.0 β†’ 1840.0
vscode incremental 13.200 β†’ 14.187 84,684,053,413 β†’ 84,683,784,649.5 2.903 β†’ 2.963 2163.1 β†’ 2161.2
xstate-main check 0.684 β†’ 0.673 5,566,808,063 β†’ 5,566,830,762.5 0.183 β†’ 0.187 241.7 β†’ 242.0
xstate-main incremental 0.664 β†’ 0.672 5,728,449,654.5 β†’ 5,728,463,574.5 0.182 β†’ 0.181 244.2 β†’ 243.2
webpack check 0.927 β†’ 0.930 10,885,421,496 β†’ 10,885,561,724.5 0.196 β†’ 0.199 404.3 β†’ 404.4
webpack incremental 1.891 β†’ 1.903 11,109,908,935.5 β†’ 11,109,853,741 0.414 β†’ 0.409 405.0 β†’ 403.4
mui-docs check 4.535 β†’ 4.356 33,106,523,180.5 β†’ 33,115,175,594.5 1.741 β†’ 1.734 1232.6 β†’ 1230.4
mui-docs incremental 2.779 β†’ 2.884 34,465,372,362.5 β†’ 34,461,094,044.5 1.117 β†’ 1.115 1163.6 β†’ 1164.0
Compiler check 0.187 β†’ 0.189 1,775,529,606.5 β†’ 1,775,524,965.5 0.083 β†’ 0.085 77.6 β†’ 76.9
Compiler incremental 0.210 β†’ 0.187 1,789,924,806 β†’ 1,789,941,499.5 0.076 β†’ 0.084 79.7 β†’ 79.6
Compiler-Unions check 0.353 β†’ 0.371 3,053,231,452.5 β†’ 3,053,238,450.5 0.150 β†’ 0.145 81.3 β†’ 81.5
Compiler-Unions incremental 0.351 β†’ 0.343 3,064,793,845.5 β†’ 3,064,735,815 0.163 β†’ 0.166 85.1 β†’ 84.9
cal-diy check 3.797 β†’ 3.337 28,974,947,079 β†’ 28,974,402,712.5 0.890 β†’ 0.903 1357.7 β†’ 1358.7
cal-diy incremental 4.037 β†’ 4.225 30,597,025,188 β†’ 30,595,427,797 1.357 β†’ 1.345 1266.2 β†’ 1266.5
formbricks-web check 4.738 β†’ 4.862 37,088,016,490.5 β†’ 37,088,432,178.5 1.268 β†’ 1.237 1583.9 β†’ 1581.3
formbricks-web incremental 4.621 β†’ 4.449 39,694,157,217 β†’ 39,692,290,239 1.210 β†’ 1.222 1625.9 β†’ 1624.9
supabase-studio check 3.965 β†’ 3.932 40,824,085,395.5 β†’ 40,824,421,547 0.962 β†’ 0.959 1309.5 β†’ 1312.6
supabase-studio incremental 4.527 β†’ 4.621 43,773,756,835 β†’ 43,771,325,967 1.271 β†’ 1.293 1365.4 β†’ 1362.9
t3code-server check 5.946 β†’ 6.332 41,059,048,826.5 β†’ 41,057,865,860.5 2.266 β†’ 2.295 1442.2 β†’ 1452.2
t3code-server incremental 6.370 β†’ 6.168 41,582,638,283 β†’ 41,586,458,288.5 2.324 β†’ 2.241 1305.8 β†’ 1305.7
mikro-orm check 8.740 β†’ 9.447 44,486,192,206.5 β†’ 44,486,470,322.5 2.244 β†’ 2.287 1277.9 β†’ 1280.3
mikro-orm incremental 5.204 β†’ 5.227 44,796,498,349 β†’ 44,796,906,680 1.321 β†’ 1.298 1255.0 β†’ 1257.9
next-packages-next check 1.810 β†’ 1.778 17,406,047,388 β†’ 17,406,122,806.5 0.414 β†’ 0.426 558.4 β†’ 561.5
next-packages-next incremental 2.149 β†’ 2.121 17,732,694,402 β†’ 17,732,623,933 0.640 β†’ 0.694 563.8 β†’ 564.4
next-root check 1.294 β†’ 1.277 13,996,499,577 β†’ 13,996,284,857.5 0.268 β†’ 0.269 430.9 β†’ 431.3
next-root incremental 1.460 β†’ 1.443 14,458,957,279 β†’ 14,458,919,889.5 0.382 β†’ 0.379 473.9 β†’ 472.1
storybook check 1.794 β†’ 1.788 8,867,478,852 β†’ 8,867,594,681.5 0.396 β†’ 0.404 396.0 β†’ 397.3
storybook incremental 1.164 β†’ 1.161 9,193,087,436.5 β†’ 9,195,172,575 0.339 β†’ 0.336 374.8 β†’ 375.8
nuxt check 0.909 β†’ 0.908 8,501,893,522.5 β†’ 8,502,041,717 0.230 β†’ 0.232 390.2 β†’ 390.9
nuxt incremental 0.899 β†’ 0.894 8,904,995,537 β†’ 8,905,231,872.5 0.239 β†’ 0.232 390.4 β†’ 391.9
playwright check 1.080 β†’ 1.067 7,403,284,419 β†’ 7,403,345,084 0.253 β†’ 0.235 358.4 β†’ 362.6
playwright incremental 1.067 β†’ 1.147 7,576,969,969.5 β†’ 7,576,754,831.5 0.305 β†’ 0.326 340.3 β†’ 341.2
drizzle-orm check 1.072 β†’ 1.056 5,948,835,699 β†’ 5,948,675,564.5 0.392 β†’ 0.395 387.0 β†’ 383.0
drizzle-orm incremental 0.708 β†’ 0.702 6,120,300,726 β†’ 6,120,412,218.5 0.235 β†’ 0.233 347.2 β†’ 346.3
typeorm check 0.882 β†’ 0.956 6,398,288,565.5 β†’ 6,398,441,122 0.218 β†’ 0.214 225.8 β†’ 226.5
typeorm incremental 0.663 β†’ 0.659 6,776,149,377 β†’ 6,776,060,624 0.173 β†’ 0.173 232.7 β†’ 233.5
date-fns check 0.673 β†’ 0.660 3,352,281,056.5 β†’ 3,352,331,540 0.212 β†’ 0.204 152.4 β†’ 152.5
date-fns incremental 0.386 β†’ 0.394 3,589,704,291.5 β†’ 3,590,188,870 0.192 β†’ 0.189 163.2 β†’ 163.7

tsrs-lint

Release tsrs-lint linting each project's source files with all 61 rules. After a warmup run of each binary, alternating main/PR pairs (10 per mode) measure wall time, CPU time and peak RSS with TSRS_FAST unset and with TSRS_FAST=1.

Project Mode Wall time Ξ” CPU time Ξ” Peak RSS Ξ” Diagnostics (main β†’ PR)
webpack default +0.1% +0.2% +0.1% 35405, identical
webpack TSRS_FAST=1 +0.4% +0.2% +0.2% 35405, identical
drizzle-orm default -1.2% -1.1% 0.0% 7057, identical
drizzle-orm TSRS_FAST=1 +1.6% +0.1% 0.0% 7057, identical
xstate-main default -1.1% -1.5% +0.5% 6489, identical
xstate-main TSRS_FAST=1 -1.0% -0.4% +0.1% 6489, identical

Negative means the PR used less. Wall and CPU time deltas are medians of paired PR/main ratios; peak RSS compares medians.

Measured lint medians (main β†’ PR)
Project Mode Wall time (s) CPU time (s) Peak RSS (MiB)
webpack default 0.406 β†’ 0.408 2.090 β†’ 2.095 463.2 β†’ 463.6
webpack TSRS_FAST=1 0.406 β†’ 0.407 2.082 β†’ 2.093 464.1 β†’ 465.0
drizzle-orm default 0.253 β†’ 0.251 1.360 β†’ 1.336 403.3 β†’ 403.2
drizzle-orm TSRS_FAST=1 0.254 β†’ 0.260 1.360 β†’ 1.366 403.8 β†’ 403.8
xstate-main default 0.372 β†’ 0.370 1.685 β†’ 1.644 341.6 β†’ 343.4
xstate-main TSRS_FAST=1 0.373 β†’ 0.372 1.653 β†’ 1.643 341.4 β†’ 341.7

gkze pushed a commit to townco/tsrs that referenced this pull request Nov 25, 2026
oxc-project#1084)

The resident-memory test from oxc-project#1083 re-runs itself in a child process through current_exe(), which Miri's
isolation rejects (readlink), and the Miri workflow runs every arena_test:: case on pushes to main. Ignore it under
Miri, and add a small test that Miri can run over the path oxc-project#1083 added: a registered region in the large slabs, found
by address beside a standard-slab region, kept across that region's free and its own trim, and unregistered on drop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

tsc -b with many projects keeps the memory of finished projects and waits on the shared parse pool (public reproduction)

2 participants