[Bug]: Android launch spends ~2 s in formatjs polyfill checks before the first render

Offen Anfängerfreundlich
#40,790 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
android, react-native, typescript

Rechercherichtung

Beginne in apps/mobile/src/i18n/intl-polyfills.ts, wo die Polyfills für DisplayNames und PluralRules aus ihren Standard-Einstiegspunkten importiert werden. Das Issue berichtet, dass die erzwungenen Einstiegspunkte (polyfill-force) dieselben APIs ohne die Prüfung der Locale-Übereinstimmung installieren, die den Start verlangsamt. Stelle die Imports um und prüfe, dass Intl.DisplayNames.polyfilled true ist, dass PluralRules('en').select(1) 'one' zurückgibt und dass DisplayNames für 'fr' 'French' zurückgibt. Fertig ist, wenn sich die Auswertungszeit der Imports auf einem Android-Release-Build verringert, gemessen mit am start -W.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Before submitting
  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.
Area

apps/mobile

Steps to reproduce
  1. Install a release Android build.
  2. Force-stop the app, then launch it (adb shell am start -W -n <package>/.MainActivity).
  3. Time the splash screen.
Expected behavior

The splash hides within about a second or two of the first JS line on a current phone.

Actual behavior

On a Pixel 9 Pro the splash stays up 5.3 to 6.1 s. Timing logs in a release build show about 3.0 s spent evaluating the JS import graph before App renders anything.

Timing each module's first evaluation (a profiling polyfill around Metro's __d) puts the two largest costs in apps/mobile/src/i18n/intl-polyfills.ts:

Module Self time (emulator, production bundle)
@formatjs/intl-displaynames/polyfill.js 619 ms
@formatjs/intl-pluralrules/polyfill.js 243 ms

Both default entries call shouldPolyfill() at import. With no native Intl.DisplayNames or Intl.PluralRules (Hermes has neither), that runs @formatjs/intl-localematcher's match(['en'], <~700 supported locales>, 'en'). Every comparison goes through the JS getCanonicalLocales polyfill, and the result is always "polyfill".

Importing the forced entries instead (@formatjs/intl-displaynames/polyfill-force and @formatjs/intl-pluralrules/polyfill-force) installs the same polyfills without the check. Measured on the same phone:

Default entries polyfill-force
JS import evaluation 2.98 to 3.08 s 0.75 to 0.96 s
Tap to splash gone (am start -W) 5.3 to 6.1 s 1.7 s warm, 2.5 to 3.6 s cold

Both APIs still install and work afterwards (Intl.DisplayNames.polyfilled === true, new Intl.PluralRules('en').select(1) === 'one', new Intl.DisplayNames(['en'], { type: 'language' }).of('fr') === 'French').

Impact

Major degradation or frequent failure

Version or commit

apps/mobile/src/i18n/intl-polyfills.ts as of c3a330d834 (unchanged in the fork build measured)

Environment

Pixel 9 Pro, Android 17 (GrapheneOS), Battery Saver on, release build; module timings from a production bundle on an Android 17 emulator

Logs or stack traces

Next-largest import costs after the change: React Native's BridgelessUIManager collecting legacy view-manager constants (~400 ms on the emulator), global.css, and Effect / packages/contracts schema setup.

Vorherrschende Sprache
TypeScript
Sterne
24.8k
Forks
6.4k
Ø Merge
2 Std. 18 Min.
Gemergte PRs (30 T.)
448

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus pingdotgg/t3code

Alle Issues in pingdotgg/t3code

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.