Skip to content

Pool argument states to reduce application size - #521

Merged
eiriktsarpalis merged 14 commits into
mainfrom
eiriktsarpalis-polytype-app-size-generation
Oct 9, 2026
Merged

eiriktsarpalis merged 14 commits into
mainfrom
eiriktsarpalis-polytype-app-size-generation

Conversation

@eiriktsarpalis

@eiriktsarpalis eiriktsarpalis commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Reduce Native AOT generic specialization by using pooled class-backed argument states for source-generated and Reflection.Emit constructors, methods, and functions.

  • Add IArgumentState.Return() and PT0033 to enforce constructor-state cleanup; generated function wrappers return states in finally.
  • Keep plain reflection and the F# fallback non-pooled through a private ReflectionArgumentState.
  • Retain the previous struct helpers as obsolete compatibility types.
  • Expand the .NET 11 size canary to 75 record types and 135 generated shapes, exercising JSON and configuration binding. Refresh all three platform baselines from native CI measurements.

Native AOT size improvement

The representative canary is 24.55–25.57% smaller than main (45dd35c). Each platform builds both library versions with identical application source and publish settings:

Platform Main libraries This PR (9a0be57) Reduction
Linux x64 6,590,120 B 4,972,504 B 24.55%
Windows x64 5,852,672 B 4,380,160 B 25.16%
macOS ARM64 6,435,328 B 4,789,840 B 25.57%

Native measurements use the pinned .NET 11 RC SDK, Release size optimization, invariant globalization, and disabled stack traces. Each runner repeated publishes in reverse order with identical sizes and successful JSON/configuration round trips. This is a file-size comparison, not a throughput claim.

Validation

make test, make pack, and make test-aot-size pass. CI is green across all six Linux/Windows/macOS Debug/Release jobs, including native-size checks. Markdown and Codecov checks also pass.

Add opt-in class-backed argument states for smaller Native AOT output, with explicit pooling return semantics and benchmark coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move pooling behavior to a dedicated interface and make the optimization-mode fixture compile with older language versions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.65217% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.33%. Comparing base (45dd35c) to head (9a0be57).

Files with missing lines Patch % Lines
...Generator/Analyzers/ArgumentStateReturnAnalyzer.cs 87.75% 7 Missing and 5 partials ⚠️
...ConfigurationBinder/ConfigurationBinder.Builder.cs 82.35% 3 Missing ⚠️
...SourceGenerator/SourceFormatter/SourceFormatter.cs 75.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #521      +/-   ##
==========================================
+ Coverage   94.29%   94.33%   +0.03%     
==========================================
  Files         255      258       +3     
  Lines       17277    17516     +239     
  Branches     3361     3393      +32     
==========================================
+ Hits        16292    16523     +231     
- Misses        747      751       +4     
- Partials      238      242       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

eiriktsarpalis and others added 3 commits October 5, 2026 21:40
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@eiriktsarpalis eiriktsarpalis changed the title Add app-size source generation mode Pool argument states to reduce application size Oct 7, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@eiriktsarpalis
eiriktsarpalis force-pushed the eiriktsarpalis-polytype-app-size-generation branch from 9565cfd to b47629c Compare October 7, 2026 18:08
eiriktsarpalis and others added 6 commits October 7, 2026 21:30
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Retain reference clearing, selectively inline returns, and initialize reused bitsets once. Align constructor snapshots across frameworks and simplify test-only release helpers.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
eiriktsarpalis and others added 2 commits October 9, 2026 19:02
Keep pooled generated/emit states, use a dedicated non-pooled reflection state, and preserve the measured small-state initialization hints. Target the canonical app at .NET 11 with representative JSON and configuration-binding shapes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use the measured Linux x64, Windows x64, and macOS ARM64 image sizes from the e865b64 Release matrix. Remove pending-baseline notices without changing tolerance settings.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@eiriktsarpalis
eiriktsarpalis merged commit 7ab0170 into main Oct 9, 2026
9 checks passed
@eiriktsarpalis
eiriktsarpalis deleted the eiriktsarpalis-polytype-app-size-generation branch October 9, 2026 17:35
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