Repository navigation
Inline NativeAOT resource keys at resource accessor call sites - #137499
MichalStrehovsky wants to merge 1 commit into
Conversation
Reuse the existing System.SR accessor-to-ldstr rewrite when System.Resources.UseSystemResourceKeys is enabled, emitting the resource key instead of its value while retaining resource-dictionary validation. Measured atop the GC size fixes, stripped NativeAOT WASI HelloWorldSize decreases from 662,805 to 659,932 bytes, saving 2,873 bytes (0.43%) and eliminating all 63 SR getter bodies. Validated the compiler build, HelloWorldSize build/run (exit 100), and direct/formatted exception messages with resource keys enabled and disabled. Co-authored-by: Copilot <[email protected]> Copilot-Session: e1b16afd-ac3c-4144-ae84-b4a37986ab3c
|
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. |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
🟡 Changes recommended
Key inlining incorrectly changes CategoryAttribute.Appearance.Category from "Appearance" to "PropertyCategoryAppearance" when resource-key mode is enabled, breaking the two-argument GetResourceString accessor’s default-text behavior.
1 open issue
What changed in this PR
Extends NativeAOT’s existing resource-accessor optimization to inline resource keys when System.Resources.UseSystemResourceKeys is enabled, reducing retained getter bodies and executable size.
Changes:
- Selects resource keys or values after validating the resource-dictionary entry.
- Enables call-site string-literal rewriting in resource-key mode and updates the explanatory comment.
| File | Description |
|---|---|
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutionProvider.cs |
Selects the key or resource value according to the feature switch. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs |
Removes the guard that prevented accessor rewriting in resource-key mode. |
Review effort: Balanced
| && dict.TryGetValue(resourceStringName, out string result)) | ||
| { | ||
| return result; | ||
| return UseResourceKeys ? resourceStringName : result; |
There was a problem hiding this comment.
That explains why I left the
// Do not attempt to inline resource strings if we only want to use resource keys.
// The optimizations are not compatible.
comment. I did push AI to explain what problems could be. I guess PR reviews have access to better models.

Reuse the existing System.SR accessor-to-ldstr rewrite when System.Resources.UseSystemResourceKeys is enabled, emitting the resource key instead of its value while retaining resource-dictionary validation.
Measured atop the GC size fixes, stripped NativeAOT WASI HelloWorldSize decreases from 662,805 to 659,932 bytes, saving 2,873 bytes (0.43%) and eliminating all 63 SR getter bodies. Validated the compiler build, HelloWorldSize build/run (exit 100), and direct/formatted exception messages with resource keys enabled and disabled.