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
+1
View File
@@ -29,6 +29,7 @@ allowBuilds:
'esbuild': false
'unrs-resolver': true
patchedDependencies:
'@formatjs/bigdecimal': patches/@formatjs__bigdecimal.patch
'@sentry/expo-upload-sourcemaps@8.18.0': patches/@sentry__expo-upload-sourcemaps@8.18.0.patch
'expo-age-range@57.0.2': patches/expo-age-range@57.0.2.patch
'expo-haptics@57.0.1': patches/expo-haptics@57.0.1.patch