Skip to content

Initialize region mappings from UTF-8 constant data - #135799

Closed
davidwrighton wants to merge 1 commit into
dotnet:mainfrom
davidwrighton:split/region-utf8
Closed

davidwrighton wants to merge 1 commit into
dotnet:mainfrom
davidwrighton:split/region-utf8

Conversation

@davidwrighton

Copy link
Copy Markdown
Member

Description

Extract the independent region-table change from #135553 onto current main.

Replace the 255-entry CultureData.RegionNames dictionary initializer with a delimited UTF-8 constant and a span-based parsing loop. Preserve the complete mapping, ordinal-ignore-case lookup, invariant-region empty value, and lazy caching. Strengthen the existing region-list test with count, comparer, representative mapping, and lowercase-lookup assertions.

Source commit: 3b299c230fc948100a0cf794d445180f1ad35c7b. This PR does not include two-phase compilation, direct calls, or the prolog/frame-identity changes.

Historical measurements and tradeoffs

These matched before/after measurements were collected on the original development branch, not on this newly extracted/rebased PR. Brotli used quality 11 and window 22.

Wasm image Raw before Raw after Raw savings Brotli before Brotli after Brotli savings
Retail CoreLib 19,140,186 19,108,544 31,642 3,586,534 3,586,536 -2
CoreLib + CallPerformance composite 12,834,328 12,809,630 24,698 2,844,562 2,809,891 34,671

The retail Brotli result is effectively neutral; the composite benefited from reduced generated initialization code. These image-dependent historical results are not a guarantee of the same savings on current main.

Cold initialization regresses: the historical native BenchmarkDotNet ShortRun, with DOTNET_ReadyToRun=0, measured the uncached dictionary construction at 5.259 us before versus 16.774 us after (3.20x), allocating 8,336 versus 24,784 bytes (2.97x). Cached access measured 5.618 versus 4.783 ns, but that tiny, short-run timing is not evidence of a reliable throughput improvement. This draft deliberately exposes the size/startup-allocation tradeoff for review.

Validation

  • git diff --check upstream/main...split/region-utf8 — passed.
  • An offline comparison of the old initializer and new UTF-8 data — passed: all 255 key/value mappings match exactly, with no duplicate keys.
  • Builds, runtime tests, and new benchmarks for this extracted branch — not run, at the user's explicit request.
  • A current-main baseline build attempted before that request failed during runtime-pack packaging because a generated libclrinterpreter.so was missing from the platform manifest. The subsequent baseline retry was stopped when the user requested no more builds.

This remains a draft; runtime validation on the independent branch is outstanding.

Note

This PR was prepared with GitHub Copilot.

Replace the CultureData region dictionary initializer with a delimited UTF-8 constant and span-based parsing loop. Preserve all mappings and lazy caching, and strengthen the existing region-list test.

Co-authored-by: Copilot <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 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.

@davidwrighton

Copy link
Copy Markdown
Member Author

I do not intend to push to merge this until we have a better indication on size improvement.

@tarekgh
tarekgh requested a balanced review from Copilot October 14, 2026 23:02
@tarekgh tarekgh added this to the 12.0.0 milestone Oct 14, 2026

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.

🔵 Needs a closer look

Current-branch runtime validation remains outstanding, and the reported size-versus-startup regression tradeoff requires maintainer judgment.

0 open findings

What changed in this PR

Replaces CoreLib’s region dictionary initializer with compact UTF-8 data to reduce generated initialization code.

Changes:

  • Parses 255 region mappings while preserving case-insensitive lookup and lazy caching.
  • Strengthens tests for entry count, comparer, representative mappings, and lowercase lookup.
File Description
src/​libraries/​System.Runtime/​tests/​System.Globalization.Tests/​System/​Globalization/​RegionInfoTests.cs Adds mapping and lookup assertions.
src/​libraries/​System.Private.CoreLib/​src/​System/​Globalization/​CultureData.cs Initializes region mappings from delimited UTF-8 data.

🧠 Review effort: Balanced

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