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

未关闭 适合新手
#40,790 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, react-native, typescript

调研方向

从 apps/mobile/src/i18n/intl-polyfills.ts 开始,该文件从默认入口导入 DisplayNames 和 PluralRules 的 polyfill。该问题报告称,强制入口(polyfill-force)安装相同的 API,但缺少会拖慢启动的 locale 匹配检查。请切换导入方式,并确认 Intl.DisplayNames.polyfilled 为 true,PluralRules('en').select(1) 返回 'one',且 'fr' 的 DisplayNames 返回 'French'。在 Android 发布版构建上,用 am start -W 测得导入的求值时间下降,即为完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
24.8k
派生
6.4k
平均合并
2 小时 18 分钟
30 天内合并 PR
448

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pingdotgg/t3code 的其他 Issue

查看 pingdotgg/t3code 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。