Repository navigation
perf(file-system): avoid per-call regex work in planFileTreeReveal - #3957
Merged
kev1n77 merged 1 commit intoNov 19, 2026
Merged
Conversation
Every reveal compiled four regexes and three closures, and stripped trailing slashes with /\/+$/ even when the last character was not a slash. On a long path-like string that anchored pattern is tried from every start position, so it scans the whole string and dominated the call. Hoist the patterns, skip the backslash pass when the input has none, and enter the trailing-slash regex only when the last character is actually a slash. Behaviour is unchanged: the lowercased copies are comparison-only, so returned paths keep the caller's casing, and remote paths keep literal backslashes.
Raing5Days
marked this pull request as ready for review
November 17, 2026 03:51
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.
Summary
planFileTreeRevealpaid for two things that do not depend on what the path means:/\/+$/ran on every call, even when the last character was not a slash. That pattern is anchored to the end, so the engine starts a match attempt at every position and the whole string is scanned — the dominant cost once the input is longer than a few characters.The slash strip now runs only when the last character actually is
/, and the backslash pass only when the input contains one.Behaviour is unchanged: the lowercased copies are comparison-only, so returned paths keep the caller's casing, and remote paths keep literal backslashes.
Validation
node scripts/run-vitest.mjs run src/tools/file-system/utils/fileTreeReveal.test.ts— 5 passed (Windows separators, remote literal backslashes, traversal rejection, workspace and filesystem root, compressed-row index)pnpm run type-check:web— passedpnpm run check:web— fails onmainat theminiapp-chrome-themegenerated-artifact check; the failing output is identical with and without this diffThe workload passes a 1.7 KB text as the path, so this measures the pathological part of the regex. Real short paths gain less; the number quoted above is this workload's, not a frame-time claim.
Generated with OpenBitFun