Skip to content

Replace embedded resource text files with inline data for Intl CLDR data#2343

Merged
lahma merged 1 commit into
sebastienros:mainfrom
lahma:inline-data
Mar 22, 2026
Merged

Replace embedded resource text files with inline data for Intl CLDR data#2343
lahma merged 1 commit into
sebastienros:mainfrom
lahma:inline-data

Conversation

@lahma

@lahma lahma commented Mar 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Convert 6 of 7 embedded .txt resource files in Jint/Native/Intl/Data/ to inline static readonly dictionary initializers in companion .Data.cs partial class files
  • Eliminates runtime text parsing, StreamReader allocations, and reflection-based GetManifestResourceStream calls
  • LikelySubtags.txt (133 KB) kept as embedded resource — inline would add ~217 KB to DLL due to UTF-16 string encoding; its loader fixed from non-thread-safe ??= to Lazy<T>
  • ComplexLanguageMapping and VariantMapping converted to readonly record struct with primary constructors
  • All dictionary initializers use exact-count capacity to avoid rehashing

Benchmark Results (BenchmarkDotNet, net10.0)

Before (embedded resources)

Method Mean Allocated
IntlNumberFormat 98.784 μs 31.03 KB
IntlDateTimeFormat 8.561 μs 29.34 KB
IntlListFormat 7.341 μs 26.41 KB
IntlRelativeTimeFormat 104.523 μs 29.07 KB
LocaleCanonicalization 8.622 μs 36.92 KB

After (inline data)

Method Mean Allocated
IntlNumberFormat 93.470 μs 31.03 KB
IntlDateTimeFormat 8.301 μs 29.34 KB
IntlListFormat 7.008 μs 26.41 KB
IntlRelativeTimeFormat 90.978 μs 29.07 KB
LocaleCanonicalization 9.576 μs 36.92 KB

Summary

Metric Change
IntlNumberFormat -5.4% faster
IntlDateTimeFormat -3.0% faster
IntlListFormat -4.5% faster
IntlRelativeTimeFormat -13.0% faster
LocaleCanonicalization +11.1% (uses Lazy<T> now for thread safety)
Memory allocations No change across all benchmarks
DLL size (net8.0) +9,728 bytes (+0.5%, from 1,878,016 to 1,887,744)

Test plan

  • dotnet test Jint.Tests — 2764+2717 passed, 0 failed
  • dotnet test Jint.Tests.Test262 — 93,300 passed, 0 failed
  • DLL size increase < 1%
  • Clean build across all targets (net462, netstandard2.0, netstandard2.1, net8.0, net10.0)

🤖 Generated with Claude Code

Convert 6 of 7 embedded .txt resource files in Jint/Native/Intl/Data/ to
inline static readonly dictionary initializers in companion .Data.cs partial
class files. This eliminates runtime text parsing, StreamReader allocations,
and reflection-based GetManifestResourceStream calls for these data files.

LikelySubtags.txt (133 KB) is kept as an embedded resource since inline
dictionary entries would add ~217 KB to the DLL due to UTF-16 string encoding.
Its loader is updated from the non-thread-safe ??= pattern to Lazy<T>.

ComplexLanguageMapping and VariantMapping structs converted to readonly record
structs with primary constructors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lahma
lahma enabled auto-merge (squash) March 22, 2026 08:08
@lahma
lahma merged commit 33e1f62 into sebastienros:main Mar 22, 2026
4 checks passed
@lahma
lahma deleted the inline-data branch March 22, 2026 08:22
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