Skip to content

refactor: Tweak metro-resolver's Node module resolution hot-path#1680

Open
kitten wants to merge 4 commits intofacebook:mainfrom
kitten:@kitten/refactor/metro-resolver/tweak-resolve-hotpath
Open

refactor: Tweak metro-resolver's Node module resolution hot-path#1680
kitten wants to merge 4 commits intofacebook:mainfrom
kitten:@kitten/refactor/metro-resolver/tweak-resolve-hotpath

Conversation

@kitten
Copy link
Copy Markdown
Contributor

@kitten kitten commented Apr 8, 2026

Summary

The current implementation in resolve.js seems slightly optimised for readability over performance, but is a hot-path that is highly impactful for bundling performance. This is slightly amplified depending on the depth of folders.

This branch aims to:

  • eliminate redundant fileSystem.lookup and instead resolve immediately and return the earliest result
  • avoid redundant array allocations and instead iterate target paths directly
  • delay building a full array of target nodeModulesPaths when a FailedToResolveNameError is constructed

While this interleaves the actual resolution, avoiding redundant work and allocations makes up for this.

A very primitive (LLM-authored) benchmark can be found here, which shows an up to 10% benefit or neutral results for resolution: kitten@a36d558

Changelog: [Internal] Refactor performance sensitive metro-resolver Node module resolution hot path

Test plan

  • CI tests should pass unchanged

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 8, 2026
@kitten kitten changed the title refactor: Tweak metro-resolver's Node module resolution hotpath refactor: Tweak metro-resolver's Node module resolution hot-path Apr 8, 2026
@facebook-github-tools facebook-github-tools bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Apr 8, 2026
@robhogan
Copy link
Copy Markdown
Contributor

robhogan commented Apr 8, 2026

Nice 👌

@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Apr 9, 2026

@robhogan has imported this pull request. If you are a Meta employee, you can view this in D100149182.

@robhogan
Copy link
Copy Markdown
Contributor

robhogan commented Apr 9, 2026

optimised for readability over performance

That's very charitable 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants