Repository navigation
perf: use a Set for visited dirs, only when resolving real paths - #175
Open
Paul-Browne wants to merge 1 commit into
Open
Paul-Browne wants to merge 1 commit into
Paul-Browne wants to merge 1 commit into
Conversation
Author
|
Related issues (none are fixed by this PR, since output is unchanged):
Heads up: this conflicts with #170 in |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
state.visitedis an array that every crawled directory is pushed into, andisRecursiveUsingRealPathsscans it withArray#includeson every directory symlink. That makeswithSymlinks()crawls (defaultresolvePaths: true) O(directories × directory symlinks).The array is also filled on every crawl, even though it is only read when
useRealPathsis set.Change
visitedis now aSet<string>, so the recursion check is O(1).options.useRealPathsis set. Otherwise it isundefined, so default crawls no longer keep a second copy of every directory path.WalkerState.visitedchanges fromstring[]toSet<string> | undefined. This type is exported, but it's internal walker state.Benchmarks
Node 22, Linux, warm page cache. Trees have N directories with one file each, plus N/2 symlinks to those directories. Crawled with
new fdir().withFullPaths().withSymlinks().crawl(root).sync(), median of 5 runs.Default crawls without symlink resolution (200k files / 10k dirs) no measurable change.