Repository navigation
[No QA] feat(telemetry): Add js module init time tracking - #83583
roryabraham merged 13 commits into
Conversation
Wraps Metro's __d() to time each module factory execution, storing results in global.__moduleInitTimes / __moduleNames. On runJsBundleEnd, logs the top 20 slowest module init times and attaches them as a Sentry breadcrumb for cold-start analysis. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@mjasikowski Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
JmillsExpensify
left a comment
There was a problem hiding this comment.
No product review required.
About the metro, it should work in release builds as well , because The only actual dev/release differences in the config are:
About web I pushed update to get same level of logging, yet that can have negative effects on the bundle size and maintenance in future webpack upgrades , (as I added webpack plugin) this is the current list in web : [Telemetry] Module init times (slowest first) — count: 50 |
| import webpack from 'webpack'; | ||
| // @libs alias is not available in Node.js/Storybook context — use relative path instead | ||
| // @ts-expect-error -- Can't use .ts extensions without allowImportingTsExtensions in tsconfig | ||
| // eslint-disable-next-line import/extensions, @dword-design/import-alias/prefer-alias |
There was a problem hiding this comment.
I added those es lint rules because using @libs caused build error in story book as it might have issue using the alias
There was a problem hiding this comment.
Hmmm ok well we should be able to fix this in the webpack config layer but we don't have to do it in this PR
|
Hey, I noticed you changed some webpack configuration files. This can break production builds. Did you remember to run a production build locally to verify they still work? |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb Safari |
|
🚧 @roryabraham has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
| }); | ||
|
|
||
| requestAnimationFrame(() => { | ||
| reportModuleInitTimes(__moduleInitTimes as Record<string, number> | undefined, __moduleNames as Record<string, string> | undefined, 100); |
There was a problem hiding this comment.
Did you try to clear the browser cache ?
There was a problem hiding this comment.
Web issue fixed after fresh npm install.
Still on mobile native. Does this require native rebuild?
|
Weird, I didn't see that 😕 |
|
I will check it again tomorrow |
|
I think it might be due to stale cache but I added typeguard safety. |
Go ahead! |
|
🚀 Deployed to staging by https://github.com/roryabraham in version: 9.3.31-0 🚀
|
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.3.31-12 🚀
|


Explanation of Change
Adds per-module initialization time tracking to help identify which src/ modules are slowest to execute during cold start.
src/setup/moduleInitPolyfill.js— a Metro polyfill that wrapsMetro's __d() global(the module definition function) to time each module's factory execution using Hermes' nativePerformanceNow clock. Results arestored in
global.__moduleInitTimes(moduleId → ms) andglobal.__moduleNames(moduleId → file path).metro.config.js — registers moduleInitPolyfill.js as a globalPrefix script so it runs before any __d() calls, ensuring every module is instrumented from the very start of bundle execution.
src/setup/telemetry/index.ts— onrunJsBundleEnd(fired via a bufferedPerformanceObserver), reads the collected times, filters tosrc/ modulesonly, sorts by slowest, takes the top 50, logs them viaconsole.debug, and attaches them as a Sentry breadcrumb (module.init category) for cold-start analysis.
src/types/global.d.ts— adds ambient type declarations for__moduleInitTimesand__moduleNamesso TypeScript is aware of the globals injected by the polyfill.Fixed Issues
#82974
Tests
Offline tests
N/A — telemetry only, no functional change. The polyfill and observer are fire-and-forget; if runJsBundleEnd never fires the data is simply not collected.
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
Verify that no errors appear in the JS console
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari