Skip to content

Optimize Intl and Temporal hot paths with caching and algorithmic fixes#2348

Merged
lahma merged 1 commit into
sebastienros:mainfrom
lahma:perf/intl-temporal-caching
Mar 22, 2026
Merged

Optimize Intl and Temporal hot paths with caching and algorithmic fixes#2348
lahma merged 1 commit into
sebastienros:mainfrom
lahma:perf/intl-temporal-caching

Conversation

@lahma

@lahma lahma commented Mar 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Cache CultureInfo instances in IntlUtilities via ConcurrentDictionary — eliminates repeated new CultureInfo() allocations across all 12+ Intl constructors
  • Cache CLDR provider data — month/weekday/day-period names, supported currencies, and currency display names computed once and cached
  • Static BigInteger constant for IsValidDuration + eliminate double[] array allocation with inline component checks
  • Reverse Windows→IANA timezone dictionary — replaces three O(n) linear scans with O(1) lookups; cache GetAvailableTimeZones() result
  • NonIsoCalendars loop fixes — cache GetMonthsInYear per iteration, direct month computation for fixed-month calendars, pre-validate leap months before try-catch
  • Minor Temporal optimizationsGetBitLength() on .NET 5+, ParseFractionDigits helper to avoid PadRight allocations, reconstruct formatted string from parts

Benchmark

Test262 suite (95,988 tests, 0 regressions):

  • Before: 43s test duration
  • After: 38s test duration
  • ~12% improvement

Test plan

  • dotnet test --configuration Release Jint.Tests.Test262/Jint.Tests.Test262.csproj — 95,988 passed, 0 failures
  • dotnet test --configuration Release Jint.Tests/Jint.Tests.csproj — 2,764 passed, 0 failures
  • Before/after timing comparison via git stash baseline

🤖 Generated with Claude Code

…es (~12% test262 speedup)

- Cache CultureInfo instances in IntlUtilities via ConcurrentDictionary
- Cache month/weekday/day-period names and currency data in DefaultCldrProvider
- Add static BigInteger constant for IsValidDuration, eliminate array allocation
- Build reverse Windows→IANA timezone dictionary for O(1) lookups
- Cache GetAvailableTimeZones result (immutable during process lifetime)
- Fix duplicate GetMonthsInYear calls per loop iteration in NonIsoCalendars
- Direct month computation for fixed-month calendars instead of year-by-year loop
- Pre-validate leap month existence before try-catch in FindCalendarReferenceYear
- Use GetBitLength() on .NET 5+ instead of ToByteArray() allocation
- Parse fraction digits directly without PadRight string allocation
- Reconstruct formatted string from parts instead of redundant Format() call

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lahma
lahma enabled auto-merge (squash) March 22, 2026 17:50
@lahma
lahma merged commit e71ae77 into sebastienros:main Mar 22, 2026
4 checks passed
@lahma
lahma deleted the perf/intl-temporal-caching branch March 22, 2026 17:56
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