Skip to content

fix(devserver): memory-conscious GC profile for the Hot Reload host - #24209

Merged
dr1rrb merged 1 commit into
masterfrom
dev/devserver-gc-profile
Aug 28, 2026
Merged

dr1rrb merged 1 commit into
masterfrom
dev/devserver-gc-profile

Conversation

@dr1rrb

@dr1rrb dr1rrb commented Aug 26, 2026

Copy link
Copy Markdown
Member

GitHub Issue: closes #24203

PR Type:

🐞 Bugfix

What changed? 🚀

The Hot Reload dev-server host (Uno.UI.RemoteControl.Host) is a long-running background daemon on the developer's machine, but it inherited the Microsoft.NET.Sdk.Web default GC profile (Server GC), which is throughput-oriented and holds onto committed memory. Under Hot Reload each emit allocates a large amount of transient garbage (tens of MB on a real app, for a ~150 KB delta); with Server GC the runtime feels no pressure to collect it, so the host's working set climbs monotonically into the multi-GB range over a working session (see #24203 / #24151).

This aligns the host's GC profile with a memory-conscious background daemon:

  • ServerGarbageCollection=false + ConcurrentGarbageCollection=true → Workstation background GC: pressure is applied early, so the transient garbage is actually collected and the working set stays bounded.
  • New runtimeconfig.template.json:
    • System.GC.ConserveMemory=5 → keeps the heap compact and decommits freed memory back to the OS (so RSS actually goes down, not just the managed heap).
    • System.GC.HeapHardLimitPercent=66 → relative last-resort ceiling (no absolute, machine-dependent value to pick).
    • System.GC.HighMemoryPercent=70 → the GC becomes aggressive earlier when the machine is under memory pressure — a good citizen on a shared dev box.

Measured (synthetic LOH churn, 40 iterations, ~27 MB live heap in all three cases) — peak / final process working set:

GC profile RSS peak RSS final
Server GC (previous default) 670 MB 534 MB
Workstation GC 387 MB 387 MB
Workstation + ConserveMemory 317 MB 317 MB (flat)

The emitted runtimeconfig.json was verified to contain the five expected System.GC.* values.

This is the fast, low-risk mitigation track. The root-cause tracks (non-incremental generators, connection/workspace lifetime, per-solution/baseline/target workspace sharing) are tracked separately in #24204, #24205, #24206 and #24207.

PR Checklist ✅

  • 🧪 Added [Runtime tests, UI tests, or a manual test sample] — N/A: runtime GC configuration only; validated by measured working-set behavior and the emitted runtimeconfig.json.
  • 📚 Docs have been added/updated following the documentation template — N/A.
  • 🖼️ Validated PR Screenshots Compare Test Run results — N/A (no UI change).
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

The dev-server host is a long-running background daemon on the developer's
machine, but inherited the Microsoft.NET.Sdk.Web default (Server GC), which is
throughput-oriented and retains committed memory. Under Hot Reload each emit
allocates tens of MB of transient garbage; Server GC feels no pressure to
collect it, so RSS climbs into multi-GB over a session.

Align the host GC profile with a memory-conscious background daemon:
- ServerGarbageCollection=false + ConcurrentGarbageCollection=true (Workstation
  background GC: pressure applied early, transient garbage collected).
- runtimeconfig.template.json: System.GC.ConserveMemory=5 (compact heap +
  decommit to OS), HeapHardLimitPercent=66 (relative last-resort ceiling),
  HighMemoryPercent=70 (react earlier under machine memory pressure).

Fixes #24203
Copilot AI lite review requested due to automatic review settings August 26, 2026 15:45
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


devid-bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

Pull request overview

This PR adjusts the GC configuration for Uno.UI.RemoteControl.Host (the Hot Reload dev-server host) to reduce working-set growth in long-running developer sessions by switching away from the Web SDK’s default Server GC profile and adding GC tuning via runtimeconfig.template.json.

Changes:

  • Switch the host to Workstation GC by setting ServerGarbageCollection=false (and explicitly enabling concurrent/background GC).
  • Add runtimeconfig.template.json with memory-conserving GC knobs (ConserveMemory, HeapHardLimitPercent, HighMemoryPercent).
  • Ensure runtimeconfig.template.json is not treated as web content to copy to output or include in packaging.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Uno.UI.RemoteControl.Host/Uno.UI.RemoteControl.Host.csproj Overrides Web SDK default Server GC and excludes runtimeconfig.template.json from Content output/packaging.
src/Uno.UI.RemoteControl.Host/runtimeconfig.template.json Adds runtime GC config properties to keep the daemon’s memory usage bounded and more responsive to system pressure.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 2m 5s —— View job


Code Review

  • Gather context — read changed files
  • Review .csproj changes
  • Review runtimeconfig.template.json
  • Post inline comments (none needed — no issues found)
  • Post summary

Verdict: LGTM — no blocking issues.

The change is technically correct, well-scoped, and well-documented. Detailed notes:

Uno.UI.RemoteControl.Host.csproj

  • ServerGarbageCollection=false + ConcurrentGarbageCollection=true are the correct MSBuild property names; they emit into the generated runtimeconfig as System.GC.Server and System.GC.Concurrent. ✓
  • Placing them in the existing top-level PropertyGroup is the right home. ✓
  • The Content Remove="runtimeconfig.template.json" ItemGroup is correct — the SDK picks up the template automatically as a build-time merge input; excluding it from Content prevents it from appearing in the publish output. ✓

runtimeconfig.template.json

  • System.GC.ConserveMemory=5 — valid range is 0–9; 5 is a reasonable midpoint that triggers decommit of freed segments back to the OS without over-aggressively compacting on every collection. ✓
  • System.GC.HeapHardLimitPercent=66 — a relative ceiling on the managed heap as a fraction of physical RAM. On a typical 16 GB dev machine this is ~10.5 GB, which will almost never be reached in practice; it's genuinely just a last-resort safety net, which is the appropriate intent here. ✓
  • System.GC.HighMemoryPercent=70 — triggers high-memory mode in the GC (machine-wide pressure, not process-level) at 70% of physical RAM, vs. the default 90%. The ordering relative to HeapHardLimitPercent is correct: on a machine where the devserver is the dominant consumer, machine RAM usage reaching 70% happens before the managed heap approaches the 66% ceiling, so the GC becomes aggressive in time to avoid OOM. ✓
  • HeapHardLimitPercent and HeapHardLimit are mutually exclusive; only the percent variant is set — no conflict. ✓
  • The three template settings are orthogonal to Server/Concurrent (which are emitted by MSBuild properties), so no duplication or collision in the merged runtimeconfig. ✓

Commit and PR form

@unodevops

Copy link
Copy Markdown
Contributor

@dr1rrb
dr1rrb merged commit 0ef10ff into master Aug 28, 2026
70 checks passed
@dr1rrb
dr1rrb deleted the dev/devserver-gc-profile branch August 28, 2026 12:21
@dr1rrb

dr1rrb commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

@Mergifyio backport release/stable/6.7

@mergify

mergify Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7

✅ Backports have been created

Details

agneszitte added a commit that referenced this pull request Sep 11, 2026
…6.7/pr-24209

fix(devserver): memory-conscious GC profile for the Hot Reload host (backport #24209)
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.

DevServer Hot Reload host: reconsider System.GC.Server (+ optional GCHeapHardLimitPercent)

5 participants