Repository navigation
perf(build): cold -b of many small projects in 26% less time and 6% less memory - #1083
Conversation
β¦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.
β¦ builder thread
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Performance change vs mainWorkflow run Β· main 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.
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)
tsrs-lintRelease
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)
|
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.
a cold
tsrs -bover 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 aRegion::newon 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 oneworker_pool(), though under-bmost rounds are a few filesthe 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--singleThreadedalready parses every round. a non-watch-pbuild reaches neither path; watch sessions get the slab change toothe #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 pairsat 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 --singleThreadedon 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'sthe 189,000 emitted
.d.ts,.d.ts.mapand.tsbuildinfofiles and stdout are byte-identical to main's. the diff adds nounsafeand leaves thetools/lint/source.mjsinventories unchanged: a registered region in large slabs only combines two flagsRegion::new_inalready takes independently. the new arena test runs in a child process through a copy of theisolatedhelper the other crates' RSS tests useFixes #1075
Co-authored-by: Christian Vuerings 127199+christianvuerings@users.noreply.github.com