Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve fast_path.resolve correctness and performance #1209

Closed
wants to merge 1 commit into from

Conversation

robhogan
Copy link
Contributor

@robhogan robhogan commented Feb 5, 2024

Correctness

Fixes a bug in fastPath.resolve where paths ending in /.. would not collapse preceding segments, eg resolve('/project/root', '../..') would return /project/.. rather than /.

This came up when implementing incremental resolution support - we end up resolving canonical paths like this during lookup of first missing directory nodes. The correctness fix is changelog-internal because Metro doesn't currently call resolve with paths like these, and this API isn't public.

Performance

In implementing this, I've also squeezed out a bit more performance so that fast_path.resolve is now about 1.6x faster than before this diff and 20x faster than path.resolve for repeated calls with the same root. This is significant because it actually dominates getRealPath, which is called hundreds of thousands of times during module resolution on a typical graph. Zoomed out benchmarks to follow in the stack.

Benchmarks

Calling resolve 2m times on different, representative (FB internal) paths per sample.

┌─────────┬───────────┬─────────┬───────────────────┬──────────┬─────────┐
│ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin   │ Samples │
├─────────┼───────────┼─────────┼───────────────────┼──────────┼─────────┤
│ 0       │ 'new'     │ '16'    │ 61555575.15459959 │ '±0.26%' │ 488     │
│ 1       │ 'old'     │ '10'    │ 99607323.81785941 │ '±0.32%' │ 302     │
│ 2       │ 'system'  │ '0'     │ 1472189198.380425 │ '±0.73%' │ 21      │
└─────────┴───────────┴─────────┴───────────────────┴──────────┴─────────┘

Changelog:

**[Performance]:** Improve resolution performance by optimising normal->absolute path conversion.

Reviewed By: motiz88

Differential Revision: D52464135

@facebook-github-bot facebook-github-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 Feb 5, 2024
@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

Summary:


## Correctness
Fixes a bug in `fastPath.resolve` where paths ending in `/..` would not collapse preceding segments, eg `resolve('/project/root', '../..')` would return `/project/..` rather than `/`.

This came up when implementing incremental resolution support - we end up resolving canonical paths like this during lookup of first missing directory nodes. The correctness fix is changelog-internal because Metro doesn't currently call `resolve` with paths like these, and this API isn't public.

## Performance
In implementing this, I've also squeezed out a bit more performance so that `fast_path.resolve` is now about 1.6x faster than before this diff and 20x faster than `path.resolve` for repeated calls with the same root. This is significant because it actually dominates `getRealPath`, which is called hundreds of thousands of times during module resolution on a typical graph. Zoomed out benchmarks to follow in the stack.

Changelog: [Performance] Improve resolution performance by optimising normal->absolute path conversion

## Benchmarks
Calling `resolve` 2m times on different, representative (FB internal) paths per sample.
```
┌─────────┬───────────┬─────────┬───────────────────┬──────────┬─────────┐
│ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin   │ Samples │
├─────────┼───────────┼─────────┼───────────────────┼──────────┼─────────┤
│ 0       │ 'new'     │ '16'    │ 61555575.15459959 │ '±0.26%' │ 488     │
│ 1       │ 'old'     │ '10'    │ 99607323.81785941 │ '±0.32%' │ 302     │
│ 2       │ 'system'  │ '0'     │ 1472189198.380425 │ '±0.73%' │ 21      │
└─────────┴───────────┴─────────┴───────────────────┴──────────┴─────────┘
```

Reviewed By: motiz88

Differential Revision: D52464135
@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in c2022d4.

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. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants