Skip to content

perf: further reduce RSS for .NET (AOT) and Java (Native) - #5

Open
davideme wants to merge 3 commits into
mainfrom
claude/thirsty-borg-4cbc06
Open

perf: further reduce RSS for .NET (AOT) and Java (Native)#5
davideme wants to merge 3 commits into
mainfrom
claude/thirsty-borg-4cbc06

Conversation

@davideme

Copy link
Copy Markdown
Owner

Summary

Aim: bring .NET (AOT) and Java (Native) RSS under 16 MB. Current baseline from the Memory workflow:

Language RSS (MB)
Go 10.8
.NET (AOT) 17.1
Java (Native) 17.9

This PR stays at the flag/config level — no HTTP API swap. If either implementation is still >16 MB after CI runs, a Phase 2 swap to System.Net.HttpListener / raw ServerSocket is the planned fallback.

Changes

Java Native (.github/workflows/memory.yml, .github/workflows/ci.yml)

  • Heap: MaxHeapSize 16m → 8m, MinHeapSize 1m → 512k, new MaxNewSize=2m. With --gc=serial, the GC sizes its committed regions against the max — lowering the cap is the single biggest expected win.
  • --enable-monitoring= — explicit empty value to assert nothing (JFR, jvmstat, heap-dump, etc.) is enabled.
  • -H:DeadlockWatchdogInterval=0 — drops the watchdog thread.

.NET AOT (dotnet/dotnet.csproj)
Eight new trimming/feature-switch properties:

  • DebuggerSupport=false, MetadataUpdaterSupport=false — drop debugger and hot-reload metadata.
  • StackTraceSupport=false + IlcGenerateStackTraceData=false — strip stack-trace string tables.
  • UseSystemResourceKeys=true — replace localized exception messages with their resource keys.
  • EnableUnsafeBinaryFormatterSerialization=false, EnableUnsafeUTF7Encoding=false — drop unused encoders.
  • IlcDisableReflection=true — most aggressive; WebApplication.CreateSlimBuilder() is the slim path so this should be safe, but it's the easiest to revert in isolation if the publish breaks.

.NET runtime config (dotnet/runtimeconfig.template.json)

  • System.GC.Concurrent: true → false — drops the background GC thread (each thread reserves ~1 MB of stack visible in RSS); this is the biggest expected .NET win.
  • System.GC.HeapHardLimit: 20 MB → 12 MB.
  • System.GC.RetainVM: false — return decommitted segments to the OS sooner.

Test plan

  • CI workflow's Build native image step still succeeds (no broken flags).
  • CI workflow's Verify HTTP 200 step still passes (server starts and responds).
  • Memory workflow report shows .NET (AOT) < 16384 KB.
  • Memory workflow report shows Java (Native) < 16384 KB.
  • If either is still >16 MB: drop Java MaxHeapSize to 4m; for .NET try removing IlcDisableReflection first (if publish failed) or lower HeapHardLimit to 10 MB.

🤖 Generated with Claude Code

davideme and others added 3 commits May 12, 2026 14:38
Target: bring both implementations under 16 MB RSS (previously 17.1 MB
and 17.9 MB respectively). Stays at flag/config level — no API swap.

Java Native (memory.yml, ci.yml):
- Lower heap: MaxHeapSize 16m → 8m, MinHeapSize 1m → 512k
- Add MaxNewSize=2m to bound young generation under serial GC
- Explicitly disable monitoring (--enable-monitoring=)
- Drop deadlock watchdog thread (-H:DeadlockWatchdogInterval=0)

.NET AOT (dotnet.csproj):
- More trimming knobs: DebuggerSupport, StackTraceSupport,
  UseSystemResourceKeys, MetadataUpdaterSupport,
  EnableUnsafeBinaryFormatterSerialization, EnableUnsafeUTF7Encoding,
  IlcGenerateStackTraceData, IlcDisableReflection

.NET runtime config:
- Disable concurrent GC to drop background GC thread
- Lower HeapHardLimit 20 MB → 12 MB
- Return decommitted VM to OS (RetainVM=false)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
GraalVM 25.0.2 rejects an empty value for --enable-monitoring; the flag
is an opt-in list (heapdump/jfr/jvmstat/...) with no "explicit none"
form, since none is already the default.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…cbc06

# Conflicts:
#	.github/workflows/memory.yml
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.

1 participant