Skip to content

Disable server GC and background GC for CoreCLR WebAssembly builds#127178

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/analyze-coreclr-gc-build-config
Draft

Disable server GC and background GC for CoreCLR WebAssembly builds#127178
Copilot wants to merge 6 commits intomainfrom
copilot/analyze-coreclr-gc-build-config

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

Description

Applies two complementary size optimizations for CoreCLR WebAssembly builds, which use the interpreter instead of the traditional JIT:

  1. Disable server GCFEATURE_SVR_GC is suppressed for WebAssembly in clrdefinitions.cmake. WebAssembly is single-threaded and has no use for server GC's multi-heap design.

  2. Disable background GC — Background GC (concurrent GC) requires WRITE_WATCH support and background threads, neither of which is available on WebAssembly. BACKGROUND_GC is now suppressed with a #ifndef TARGET_WASM guard in gcpriv.h. The datadescriptor.h and datadescriptor.inc cDAC descriptor files are updated to guard the fields and globals that only exist when BACKGROUND_GC is defined.

Size measurements (corerun.wasm)

Configuration Raw (bytes) Brotli (bytes)
Original baseline 4,264,779 1,283,871
Disable server GC + background GC 4,171,449 1,258,272
Total savings 93,330 (2.2%) 25,599 (2.0%)

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/ef405ab1-bc2a-472f-b797-52d49c5d8409

Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

@janvorli
Copy link
Copy Markdown
Member

@copilot let's disable the background GC for WASM too.

@janvorli
Copy link
Copy Markdown
Member

cc: @radekdoulik FYI

Copilot AI requested review from Copilot and removed request for Copilot April 20, 2026 21:19
…eLoadedBeforeCodeIsRun, and reportTailCallDecision

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/05b0c780-4d5e-4177-b5ec-c07a31e050a7

Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 20, 2026 21:37
Copilot AI requested review from Copilot and removed request for Copilot April 20, 2026 21:56
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 20, 2026

@copilot let's disable the background GC for WASM too.

Done in dc7b9f9. Added #ifndef TARGET_WASM guard around #define BACKGROUND_GC in gcpriv.h, and updated datadescriptor.h and datadescriptor.inc to guard the fields that only exist when BACKGROUND_GC is defined.

Additional savings from disabling background GC: 47,527 bytes raw / 15,680 bytes brotli, bringing the total vs baseline to 93,330 bytes raw (2.2%) / 25,599 bytes brotli (2.0%).

Copilot AI changed the title Disable server GC for CoreCLR WebAssembly builds Reduce CoreCLR WebAssembly binary size: stub unused JIT interface methods and disable background GC Apr 20, 2026
@janvorli
Copy link
Copy Markdown
Member

@copilot please undo the changes in the jitinterface.cpp, these are unrelated to the GC changes.

Copilot AI requested review from Copilot and removed request for Copilot April 20, 2026 22:11
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 20, 2026

@copilot please undo the changes in the jitinterface.cpp, these are unrelated to the GC changes.

Done in c6d22cb. The jitinterface.cpp changes have been reverted — the PR now only contains the GC-related changes (gcpriv.h, datadescriptor.h, datadescriptor.inc, and the clrdefinitions.cmake server GC disable).

Copilot AI changed the title Reduce CoreCLR WebAssembly binary size: stub unused JIT interface methods and disable background GC Disable server GC and background GC for CoreCLR WebAssembly builds Apr 20, 2026
GC_HEAP_FIELD(OomData, oom_info)

/* For use in GCHeapDetails APIs */
#ifdef BACKGROUND_GC
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.

@davidwrighton is this ok for CDAC, assuming that disabling background GC is a WASM only thing?

Copilot AI review requested due to automatic review settings April 21, 2026 06:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR applies CoreCLR WebAssembly-specific build/feature gating to reduce binary size by removing GC modes that are not intended to be used/supported on WASM builds.

Changes:

  • Suppress FEATURE_SVR_GC for WebAssembly targets in CoreCLR CMake definitions.
  • Disable BACKGROUND_GC when compiling for TARGET_WASM.
  • Update GC cDAC descriptors to only describe background-GC-only fields/globals when BACKGROUND_GC is defined.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/gc/gcpriv.h Guards BACKGROUND_GC so it is not enabled for TARGET_WASM.
src/coreclr/gc/datadescriptor/datadescriptor.h Wraps background-GC-only gc_heap field descriptors in #ifdef BACKGROUND_GC.
src/coreclr/gc/datadescriptor/datadescriptor.inc Wraps background-GC-only cDAC globals in #ifdef BACKGROUND_GC.
src/coreclr/clrdefinitions.cmake Avoids defining FEATURE_SVR_GC for WASM target builds.

Comment thread src/coreclr/gc/gcpriv.h

#ifndef TARGET_WASM
#define BACKGROUND_GC //concurrent background GC (requires WRITE_WATCH)
#endif //!TARGET_WASM
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

The #endif trailing comment style here is inconsistent with the surrounding codebase (typically #endif // !TARGET_WASM with a space after //). Consider adjusting this for consistency/readability.

Suggested change
#endif //!TARGET_WASM
#endif // !TARGET_WASM

Copilot uses AI. Check for mistakes.
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.

5 participants