Skip to content

Use server GC and turn off dynamic PGO in released binaries - #93

Merged
Bobris merged 1 commit into
bobril:masterfrom
sedlakr:perf/runtime-gc-config
Oct 29, 2026
Merged

Bobris merged 1 commit into
bobril:masterfrom
sedlakr:perf/runtime-gc-config

Conversation

@sedlakr

@sedlakr sedlakr commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Problem

A build is a short (tens of seconds), CPU bound, allocation heavy process, but the released binary runs with the default settings: workstation GC and dynamic PGO. Sampling a cold build of a large project (dotnet-trace, sampled thread time) shows the single threaded bundler and the crawl thread spending seconds suspended for GC (Thread.PollGC ~4.6 s in the bundler, ~2 s in the crawl), and with ReadyToRun code the instrumented tier-0 recompilation of hot methods does not pay off in such a short run.

Change

bb/bb.csproj adds System.GC.Server=true and TieredPGO=false to the runtime config. (<ServerGarbageCollector> alone did not end up in bb.runtimeconfig.json of the trimmed, self-contained publish here, so it is set as a RuntimeHostConfigurationOption.)

Results

phoenix nsi-bobwai (2650 sources, tsrs), Windows, 18 logical cores, 63 GB, ReadyToRun publish of 7.1.0 with and without this change, alternating runs:

before after
bb b --nocache 26.8 / 26.9 / 29.0 s 21.4 / 22.8 / 22.9 / 23.1 s
bb b with build cache 19.4 / 20.0 / 21.5 / 22.4 s 16.9 / 16.9 / 17.5 / 18.2 s
peak working set ~605 MB ~775 MB
bb --version ~280 ms ~300-390 ms

Each setting alone (env DOTNET_gcServer=1 / DOTNET_TieredPGO=0 on the stock 7.0.6 and 7.1.0 binaries) helps as well: roughly -3 to -6 s for server GC and -2 to -3 s for PGO off, with some noise, so I kept both.

Output is not affected (runtime settings only). DOTNET_gcServer=0 and DOTNET_TieredPGO=1 restore the previous behavior.

Please review

  • Only measured on one 18 core Windows machine. Server GC creates a heap and thread per core, so please check a CI agent with few cores and Linux/macOS; limiting heaps with System.GC.HeapCount (and GCHeapAffinitizeMask) is an option if memory is a concern.
  • bb also runs as a long lived dev server (watch mode); I did not measure memory there. System.GC.ConserveMemory could be added if server GC keeps too much.

🤖 Generated with Claude Code

A build is a short, CPU bound, allocation heavy run. On a 2650 source project (18 cores) cold build
went from ~27 s to ~22 s, build with source cache from ~20 s to ~17 s, for ~170 MB more memory.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@Bobris Bobris left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the runtime configuration and changelog. No blocking findings. CI is green on Linux, Windows and macOS. Independently published the trimmed, self-contained ReadyToRun osx-arm64 executable, verified System.GC.Server=true and System.Runtime.TieredPGO=false in its generated runtimeconfig, and successfully built TestProjects/BbApp without the build cache with DOTNET_PROCESSOR_COUNT=2. The documented memory/startup tradeoff is acceptable.

@Bobris
Bobris merged commit f3fece9 into bobril:master Oct 29, 2026
3 checks passed
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.

2 participants