Skip to content

perf(i18n): cache Intl formatters to reduce repeated construction ove…#823

Merged
RUKAYAT-CODER merged 3 commits into
rinafcode:mainfrom
dubemoyibe-star:perf/intl-formatter-cache
Jun 29, 2026
Merged

perf(i18n): cache Intl formatters to reduce repeated construction ove…#823
RUKAYAT-CODER merged 3 commits into
rinafcode:mainfrom
dubemoyibe-star:perf/intl-formatter-cache

Conversation

@dubemoyibe-star

Copy link
Copy Markdown
Contributor

Summary

This PR improves formatting performance by introducing a shared cache for Intl.NumberFormat and Intl.DateTimeFormat instances.

Previously, formatter instances were recreated on every formatting call inside i18nUtils.ts. Since Intl constructor calls are significantly more expensive than invoking .format() on existing instances, frequently rendered components such as countdowns, dashboards, and data tables could incur unnecessary overhead.

Changes

Added formatter cache

Created a new shared utility:

  • src/utils/intlCache.ts

The cache:

  • Uses a Map keyed by serialized locale and options.
  • Reuses existing formatter instances for identical configurations.
  • Prevents repeated Intl constructor calls.

Updated i18n utilities

Refactored src/utils/i18nUtils.ts to:

  • Replace direct new Intl.NumberFormat(...) calls.
  • Replace direct new Intl.DateTimeFormat(...) calls.
  • Use the shared formatter cache instead.

Performance testing

Added benchmark coverage to validate that:

  • Repeated formatting operations reuse cached instances.
  • Formatter construction only occurs once per locale/options combination.
  • Cached formatting provides substantial performance improvements over repeated construction.

Benefits

  • Reduced render-time overhead.
  • Lower allocation pressure.
  • Improved performance in frequently updated components.
  • Consistent formatter reuse across the application.
  • Better scalability for tables, dashboards, and live UI updates.

Validation

  • Identical locale and options reuse the same formatter instance.
  • No direct Intl.NumberFormat or Intl.DateTimeFormat construction remains outside the cache module.
  • Performance tests demonstrate significant speed improvements for repeated formatting operations.

Closes #732

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@dubemoyibe-star Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER RUKAYAT-CODER merged commit ea85331 into rinafcode:main Jun 29, 2026
4 checks passed
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.

[Performance] Intl number and date formatters recreated on every call in i18nUtils.ts

2 participants