Patch @formatjs/bigdecimal with identity fast paths for div/times by 1

ECMA-402's ToRawFixed runs on every Intl.NumberFormat format call and every
Intl.PluralRules select, and both rounding candidates do
`.div(roundingIncrement)` and `.times(roundingIncrement)` where
roundingIncrement defaults to 1. Without a fast path, div(1) performs a
10^34 BigInt scale-up, a BigInt division, and a trailing-zero strip that
undoes the scaling - pure waste that profiled at 7.3% of JS-busy self time
(the `div` frame) during a heavy release-build feed scroll, because this app
force-installs the formatjs polyfill (see src/locale/i18n.ts).

The patch returns the existing immutable instance when multiplying or
dividing by exactly 1 (mantissa 1n, exponent 0 - the normalized
representation of 1).

Verified: byte-identical output across 104,800 assertions (4 locales x 3
option sets x ~8,700 values through NumberFormat.format plus
PluralRules.select), and 2.4x faster per compact format call in Node.

Candidate for upstreaming to formatjs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Tomek Zawadzki
2026-08-31 13:08:32 +02:00
parent e1f75c2c01
commit 94cbd85480
3 changed files with 35 additions and 3 deletions
+4 -3
View File
@@ -217,6 +217,7 @@ overrides:
packageExtensionsChecksum: sha256-KbeCj471Qk3TA758q8nLPkiGCPDA0TX18iO/Coy89lo=
patchedDependencies:
'@formatjs/bigdecimal': 53afe18a845c1469b8b9002a460582559dfd52f502bc66a0f4c05662c2619291
'@sentry/expo-upload-sourcemaps@8.18.0': 2368e1e1986165e7ead3c60017b78b2f9ade1b6a6b2f5ad27cd428608c6f12ae
expo-age-range@57.0.2: c325225749993424461eeece1d97a99b19c00da2ebc958a73c12e4eca0c39306
expo-haptics@57.0.1: b33910ba2753c4eccdc885b449e6e33aa90b9cefa75ca8639762a26013141410
@@ -11345,7 +11346,7 @@ snapshots:
'@floating-ui/utils@0.2.11': {}
'@formatjs/bigdecimal@0.2.5': {}
'@formatjs/bigdecimal@0.2.5(patch_hash=53afe18a845c1469b8b9002a460582559dfd52f502bc66a0f4c05662c2619291)': {}
'@formatjs/fast-memoize@3.1.5': {}
@@ -11366,12 +11367,12 @@ snapshots:
'@formatjs/intl-numberformat@9.3.10':
dependencies:
'@formatjs/bigdecimal': 0.2.5
'@formatjs/bigdecimal': 0.2.5(patch_hash=53afe18a845c1469b8b9002a460582559dfd52f502bc66a0f4c05662c2619291)
'@formatjs/intl-localematcher': 0.8.9
'@formatjs/intl-pluralrules@6.3.9':
dependencies:
'@formatjs/bigdecimal': 0.2.5
'@formatjs/bigdecimal': 0.2.5(patch_hash=53afe18a845c1469b8b9002a460582559dfd52f502bc66a0f4c05662c2619291)
'@formatjs/intl-localematcher': 0.8.9
'@formatjs/intl-supportedvaluesof@2.3.7':