forked from facebook/metro
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolver perf: Implement TreeFS.hierarchicalLookup for getClosestPack…
…age (2/n) (facebook#1287) Summary: Pull Request resolved: facebook#1287 Implement a new method on `TreeFS` that is able to "natively" perform hierarchical lookup, such as frequently used during node_modules resolution, config path resolution, etc., and use it initially to find the closest package scope of a given candidate path (`context.getClosestPackage()`). This operation currently dominates resolution time, with an algorithm that uses repeated `path.dirname()` and `fileSystem.lookup()`. The current algorithm is O(n^2) on path segments (~length), because the outer loop is O(n) and each lookup is O(n) - additionally, it's slow in constant time because each `path.dirname()` and `path.join()` involves unnecessarily parsing and normalising their own outputs - `path.join()` calls alone account for >30% of resolution time. The new implementation: - Performs a lookup on the start path, collecting a list of all nodes along the way. - Looks back through each node, and checks for the existence of the subpath on each one. *Benchmarks based on collecting and running all resolutions performed during a build of rn-tester:* ## Before - Total resolution time: 1210ms - Time in `getClosestPackage`: 910ms ## After - Total resolution time: 390ms (~3x faster) - Time in `getClosestPackage`: 105ms (~9x faster) Reviewed By: motiz88 Differential Revision: D58062988
- Loading branch information
1 parent
021e890
commit 576f6b9
Showing
7 changed files
with
746 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.