facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.24k stars 626 forks source link

Resolver perf: Optimise package exports `flattenLegacySubpathValues` (1/n) #1318

Closed robhogan closed 3 months ago

robhogan commented 3 months ago

Summary: The performance results from this stack are based on replaying the ~3000 resolutions performed during bundling RN Tester directly through DependencyGraph.resolveDependency. The baseline resolution time is ~1500ms on an M1 Max. (Internal: details in test plan)

This is a self-contained optimsation to the flattenLegacySubpathValues step as part of exports map normalisation, which takes over 20% (360ms) of total resolver CPU time over 655 calls due largely to repeated object allocations and spreads. By mutating an intermediate object instead we get this down to ~16ms.

Note that this still preserves key order - export maps are ordered.

This reduces total resolution time from 1540ms -> 1171ms (-23%)

Differential Revision: D56701232

facebook-github-bot commented 3 months ago

This pull request was exported from Phabricator. Differential Revision: D56701232

facebook-github-bot commented 3 months ago

This pull request was exported from Phabricator. Differential Revision: D56701232

facebook-github-bot commented 3 months ago

This pull request has been merged in facebook/metro@021e8906fc9a15be37eab228316922f006a59374.