Skip to content

Cut local API generation from about 3 minutes to 45 seconds - #4980

Merged
reakaleek merged 1 commit into
mainfrom
api-generation-speed-f4faa015
Nov 20, 2026
Merged

reakaleek merged 1 commit into
mainfrom
api-generation-speed-f4faa015

Conversation

@reakaleek

Copy link
Copy Markdown
Member

Debug builds of docs-builder now run with server GC. On an 18-core machine the first /api/ request of serve drops from 142 to 203 s to 40 to 49 s.

Affects: API reference, Deploys & previews

Prompt summary: The author asks why API generation takes 3 minutes and whether it can be faster. The goal is a shorter wait on the first API page of a local serve.

Why

API generation renders every version tree on all cores and allocates heavily. Debug builds ran workstation GC, which collects on one heap. The render threads stalled on that collector, so the process used about 4 of 18 cores. Only the dev container avoided this, through a DOTNET_gcServer variable.

What

Server GC for Debug builds

Every local entry point now gets server GC: mise run serve, mise run watch, the journeys tasks and a plain dotnet run. The setting lives in docs-builder.csproj and applies to the Debug configuration only. Release and AOT builds are unchanged.

One place for the setting

The dev container runs the Debug build, so the project setting covers it. The DOTNET_gcServer variable in build/dev/docker-compose.yml is gone.

Measurements

Each row is the first /api/elasticsearch/ request of a fresh serve on an 18-core machine, with 22 version trees.

Build Wall time Peak memory Runs
Debug, before 142 to 203 s 12.9 to 14.5 GB 5
Debug, after 40 to 49 s 8.9 to 9.6 GB 4
Debug, after, limited to 4 cores 36 s 10.6 GB 1

Verify

mise run serve
# in a second terminal, once the server answers:
curl -s -o /dev/null -w "%{time_total}s\n" http://localhost:3000/api/elasticsearch/

The runtime configuration of the build shows the setting:

grep "System.GC.Server" .artifacts/bin/docs-builder/debug/docs-builder.runtimeconfig.json

Risk The assembler-preview.yml and docs-preview-local.yml workflows run a Debug build, so they pick up server GC. The run limited to 4 cores used less memory than before, but no GitHub runner was measured.

Out of scope Release and AOT builds keep workstation GC. One Release run went from 101 s to 38 s with server GC, so the same setting is a candidate there once runner memory is measured.

🤖 Generated with Claude Code

API generation renders every version tree on all cores and allocates heavily. Workstation GC collects on one heap, so the render threads stalled on it. On an 18-core machine the first `/api/` request of `serve` took 142 to 203 s and now takes 40 to 49 s.

The dev container set `DOTNET_gcServer` for the same reason. It runs the Debug build, so the project setting replaces the variable.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@reakaleek
reakaleek requested a review from a team as a code owner November 20, 2026 08:38
@reakaleek
reakaleek requested a review from technige November 20, 2026 08:38

<!-- API generation allocates from every core at once. Workstation GC collects on one heap and made it 4x slower. -->
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<ServerGarbageCollection>true</ServerGarbageCollection>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: P3 (Low)

Add a build smoke check that verifies System.GC.Server is enabled in the generated Debug runtime config and not enabled in Release. Now that Compose no longer sets GC mode, a regression in this property could bring back the slow first API request while builds and functional tests still pass.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

@github-actions

Copy link
Copy Markdown
Contributor

@reakaleek
reakaleek merged commit ba1357b into main Nov 20, 2026
50 checks passed
@reakaleek
reakaleek deleted the api-generation-speed-f4faa015 branch November 20, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant