Skip to content

refactor: Tweak metro-file-map's Node crawler hot-path#1677

Open
kitten wants to merge 8 commits into
react:mainfrom
kitten:@kitten/refactor/metro-file-map/tweak-node-crawler-hotpath
Open

refactor: Tweak metro-file-map's Node crawler hot-path#1677
kitten wants to merge 8 commits into
react:mainfrom
kitten:@kitten/refactor/metro-file-map/tweak-node-crawler-hotpath

Conversation

@kitten

@kitten kitten commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Summary

When a larger amount of paths are being crawled, the Node crawler becomes a hot-path and minor tweaks can have a larger impact on startup time, than previously anticipated (at least for Expo projects)

  • Prevent repeated visits to same directories (high impact for repeated watch folders)
  • Remove repeated absoluteToNormal calls (medium impact)
  • Add a dictionary for extensions lookup (very low impact)
  • Strip forEach calls for for-of (formatting only; virtually no impact)
  • Refactor Promise code (no impact, just formatting)

I don't currently have benchmarks for the above, and it's derived from running apps/router-e2e on expo/expo's main branch and modifying metro-file-map's Node crawler.

Changelog: [Internal] Refactor performance sensitive Node crawler hot path in metro-file-map

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
@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
Comment thread packages/metro-file-map/src/crawlers/node/index.js Outdated
@kitten kitten force-pushed the @kitten/refactor/metro-file-map/tweak-node-crawler-hotpath branch from 59a90f5 to 416901a Compare April 9, 2026 11:37
@kitten kitten force-pushed the @kitten/refactor/metro-file-map/tweak-node-crawler-hotpath branch from ea59e3f to c46237d Compare April 11, 2026 12:59
kitten added 4 commits April 11, 2026 14:01
A previous implementation kept a `visited` set in the Node crawler.
Instead, we can also deduplicate and remove overlapping roots
(directories within other roots) in the `FileMap` preemptively for all
crawlers to prevent duplicate crawls.
@kitten kitten force-pushed the @kitten/refactor/metro-file-map/tweak-node-crawler-hotpath branch from c46237d to c1cea5c Compare April 11, 2026 13:01
kitten added a commit to expo/expo that referenced this pull request May 5, 2026
meta-codesync Bot pushed a commit that referenced this pull request May 11, 2026
…ceNodeFilesystemAPI` flag) (#1693)

Summary:
This is a proposal to drop the native find binary crawler code path entirely.

We've recently dropped the native find binary crawler in Expo, which was accidentally activated in some cases. We discovered (which is particularly obvious on large projects/repos and `expo/expo` itself) that it's consistently much slower than the Node FS crawler.

To get into the "correct" preference and use the Node crawler, we're currently forcing `useWatchman: null`, which then defaults to use watchman, if it's installed, but falls back to `forceNodeFilesystemAPI: true`. This is outside of what the types specify as valid, but is the cleanest way to disable the native find binary crawling.

This crawler basically just adds overhead over the Node.js implementation and is consistently slower, and less efficient, while the Node crawler is pretty optimised already (and has very low overhead once #1677 is merged)

The timings of the native find binary crawler in `expo/expo` was also observed to scale with the size of this repo, compared to a minimal reproduction, so the overhead isn't just limited to the child process call and result parsing.

Changelog: [Internal] Drop native find binary crawler and remove `forceNodeFilesystemAPI` flag

Pull Request resolved: #1693

Test Plan:
- Existing tests should pass
- Quick generated script to play around with and assess the crawlers' comparative performance: kitten@74dffd4

Reviewed By: huntie

Differential Revision: D101985455

Pulled By: robhogan

fbshipit-source-id: efe2ab02fc5c0edac4d68f037db57c635fef8e50
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