Skip to content

Add some ifdefs to allow trimming more GC code - #137498

Merged
MichalStrehovsky merged 3 commits into
dotnet:mainfrom
MichalStrehovsky:gc-size-fixes
Nov 16, 2026
Merged

MichalStrehovsky merged 3 commits into
dotnet:mainfrom
MichalStrehovsky:gc-size-fixes

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

2.5% size savings for a WASI Hello World. The individual commits have concrete numbers.

MichalStrehovsky and others added 3 commits November 13, 2026 22:08
Allow the compiler to eliminate unsupported heap-decommit paths while preserving the mutable setting on other platforms.

Reduces stripped NativeAOT WASI HelloWorldSize from 679,537 to 677,542 bytes, saving 1,995 bytes (0.29%). Validated the WASI Release NativeAOT runtime build and HelloWorldSize build/run (exit 100).

Co-authored-by: Copilot <[email protected]>
Copilot-Session: e1b16afd-ac3c-4144-ae84-b4a37986ab3c
Define FEATURE_HOST_TRACE for CoreCLR and compile GC host-error logging calls away when it is unavailable, avoiding discarded formatting in NativeAOT.

Reduces stripped NativeAOT WASI HelloWorldSize from 677,542 to 665,974 bytes, saving 11,568 bytes (1.71%). Validated the WASI Release NativeAOT runtime build, CoreCLR GC logging compilation, and HelloWorldSize build/run (exit 100).

Co-authored-by: Copilot <[email protected]>
Copilot-Session: e1b16afd-ac3c-4144-ae84-b4a37986ab3c
Keep manual-reset and auto-reset event state without pthread synchronization when FEATURE_MULTITHREADING is disabled. Return timeout for unsignaled polling and assert/fail for unsupported blocking waits, matching the existing single-threaded event policy.

Reduces stripped NativeAOT WASI HelloWorldSize from 665,974 to 662,805 bytes, saving 3,169 bytes (0.48%). Validated the WASI Release NativeAOT runtime build and HelloWorldSize build/run (exit 100), syntax-checked the threaded branch, and confirmed the single-threaded GCEvent object has no pthread references.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: e1b16afd-ac3c-4144-ae84-b4a37986ab3c
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @anicka-net, @dotnet/gc
See info in area-owners.md if you want to be subscribed.

@janvorli janvorli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you!

Copilot AI 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.

🟡 Changes recommended

Finite GC notification waits incorrectly assert or return Failed instead of timing out, so the unsupported-blocking assertion must be limited to infinite waits.

1 open issue
What changed in this PR

This PR adds compile-time guards to make GC code easier to trim for WebAssembly applications. The description reports a 2.5% size reduction for a WASI Hello World.

Changes:

  • Adds a lightweight GC event implementation for single-threaded builds.
  • Makes the WebAssembly “never decommit” setting a compile-time constant.
  • Guards GC initialization logging behind FEATURE_HOST_TRACE, enabled for CoreCLR.

Review was source-only; builds and tests were not run.

File Description
src/​coreclr/​gc/​unix/​events.cpp Adds single-threaded events without pthread synchronization.
src/​coreclr/​gc/​init.cpp Skips runtime assignment of the WebAssembly decommit setting.
src/​coreclr/​gc/​gcpriv.h Declares the decommit setting as constant on WebAssembly.
src/​coreclr/​gc/​gccommon.cpp Conditionally compiles initialization-error logging.
src/​coreclr/​gc/​gc.h Removes logging calls when host tracing is disabled.
src/​coreclr/​gc/​gc.cpp Omits mutable decommit-setting storage on WebAssembly.
src/​coreclr/​clrdefinitions.cmake Enables host tracing for CoreCLR builds.

Review effort: Balanced

Comment thread src/coreclr/gc/unix/events.cpp Resolved
@MichalStrehovsky
MichalStrehovsky enabled auto-merge (squash) November 16, 2026 09:28
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/ba-g failure is #137545

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky
MichalStrehovsky merged commit 2965bc0 into dotnet:main Nov 16, 2026
115 of 118 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the gc-size-fixes branch November 16, 2026 11:43
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-GC-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants