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

Aberta Para iniciantes
#40,790 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
72/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
android, react-native, typescript

Direção de pesquisa

Comece em apps/mobile/src/i18n/intl-polyfills.ts, onde os polyfills de DisplayNames e PluralRules são importados dos seus entry points padrão. A issue relata que os entry points forçados (polyfill-force) instalam as mesmas APIs sem a verificação de correspondência de locale que deixa a inicialização lenta. Troque os imports e confirme que Intl.DisplayNames.polyfilled é true, que PluralRules('en').select(1) retorna 'one' e que DisplayNames de 'fr' retorna 'French'. Está concluído quando o tempo de avaliação dos imports cair em um build de release Android, medido com am start -W.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
TypeScript
Estrelas
24.8k
Forks
6.4k
Merge médio
2h 18min
PRs com merge (30d)
448

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de pingdotgg/t3code

Todas as issues de pingdotgg/t3code

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.