Skip to content

Avoid culture cache lookup in invariant predefined-only mode - #137333

Merged
MichalStrehovsky merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:size/invariant-culture-compareinfo
Nov 12, 2026
Merged

MichalStrehovsky merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:size/invariant-culture-compareinfo

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Make the absence of user overrides explicit in CultureInfo.CompareInfo when both invariant globalization and predefined-only cultures are enabled. This lets NativeAOT trim the otherwise retained named-culture cache lookup. Preserve the existing sharing path when named invariant cultures are allowed.

Standalone local HelloWorldSize probe, WASI NativeAOT Release, invariant globalization and size optimization: 722,933 -> 716,024 bytes, saving 6,909 bytes (0.96%) against the common base.

Validated with clr.nativeaotlibs+libs.sfx and the HelloWorldSize build. HelloWorldSize ran under Wasmtime and exited 100.

Make the absence of user overrides explicit in CultureInfo.CompareInfo
when both invariant globalization and predefined-only cultures are
enabled. This lets NativeAOT trim the otherwise retained named-culture
cache lookup. Preserve the existing sharing path when named invariant
cultures are allowed.

Standalone local HelloWorldSize probe, WASI NativeAOT Release, invariant
globalization and size optimization: 722,933 -> 716,024 bytes, saving
6,909 bytes (0.96%) against the common base.

Validated with clr.nativeaotlibs+libs.sfx and the HelloWorldSize build.
HelloWorldSize ran under Wasmtime and exited 100.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 2e62c26c-6da8-442d-98ac-dcb988c2846a
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

All three #137333, #137332, #137331 combined save 50 kB, which is a lot more then each individually. Maybe I should have made a single PR but I assumed we might need to iterate on some.

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.

🟢 Approval recommended

No active review issues are recorded for the globalization-mode guard change.

No open issues 🎉

What changed in this PR

This PR makes the invariant, predefined-only globalization path explicit in CultureInfo.CompareInfo, allowing NativeAOT to trim the unused named-culture cache lookup.

Changes:

  • Bypasses the cache lookup when both invariant globalization and predefined-only cultures are enabled.
  • Preserves existing CompareInfo sharing when named invariant cultures are allowed.
File Description
src/​libraries/​System.Private.CoreLib/​src/​System/​Globalization/​CultureInfo.cs Adds a globalization-mode guard to the CompareInfo getter to enable trimming.

Review effort: Balanced

@tarekgh tarekgh added this to the 12.0.0 milestone Nov 11, 2026
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/ba-g timeout in the osx-arm64 leg but everything else looks good

@MichalStrehovsky
MichalStrehovsky enabled auto-merge (squash) November 12, 2026 04:23
@MichalStrehovsky
MichalStrehovsky merged commit 0b62e25 into dotnet:main Nov 12, 2026
133 of 136 checks passed
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.

3 participants