-
-
Notifications
You must be signed in to change notification settings - Fork 161
perf(module): memoize module path canonicalization per directory #10347
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
Closed
proggeramlug
wants to merge
1
commit into
PerryTS:main
from
proggeramlug:perf/module-path-canonicalize-memo-v2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Module path canonicalization is memoized per directory. Registering a module | ||
| canonicalizes its absolute path, and `std::fs::canonicalize` is a full | ||
| realpath: one `readlink` for every path component, every time. Sibling modules | ||
| share every ancestor, so the same prefixes were re-walked once per module. | ||
|
|
||
| Running `opencode --version` issued 86,745 `readlink` calls over only 9,467 | ||
| distinct paths — 98.7% of every syscall the process made and 0.32s of system | ||
| time. The tree root alone was resolved 7,501 times and `node_modules/.bun` | ||
| 5,580 times. | ||
|
|
||
| Directories are now resolved once and reused, so each additional module in a | ||
| directory costs one `readlink` for its own basename instead of one per path | ||
| component: a 400-module fixture drops from 4,010 `readlink` calls to 405. A | ||
| path containing `.` or `..` components, or a basename that really is a symlink, | ||
| still goes through `std::fs::canonicalize`, so resolution semantics are | ||
| unchanged. This is wall-clock, not instruction count — it moves `instructions:u` | ||
| by 0.04%. |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 21521
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
Preserve the original-path fallback when
read_linkerrors.read_linkerrors for missing and inaccessible basenames. In bothcanonical_dirandcanonicalize_module_path, returningjoinedthen canonicalizes a symlinked parent even when the basename is missing. A removed module can therefore resolve through an alias to the canonical target key and match a registered module throughjs_require_path_moduleorjs_has_path_module.On any probe error, canonicalize the original
dirorcandidateand retain the original input if that fails. Usejoinedonly after confirming that the basename is not a symlink.🤖 Prompt for AI Agents