-
Notifications
You must be signed in to change notification settings - Fork 1
β‘ Bolt: Optimize GitProvider string parsing hot-path #296
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,16 +53,46 @@ export class GitProvider { | |
| private readonly isWindows = process.platform === 'win32'; | ||
|
|
||
| private addFilesToSet(set: Set<string>, root: string, output: string): void { | ||
| const lines = output.split('\n'); | ||
| for (const line of lines) { | ||
| const trimmed = line.trim(); | ||
| if (trimmed) { | ||
| let filePath = path.normalize(path.join(root, trimmed)); | ||
| // β‘ Bolt: Fast string processing optimization | ||
| // Replaces .split('\n') and .trim() with a single-pass manual loop, | ||
| // and path.normalize(path.join()) with direct string concatenation. | ||
| // This avoids intermediate string/array allocations and expensive path parsing. | ||
| if (output.length === 0) return; | ||
|
|
||
| let lastIndex = 0; | ||
| const len = output.length; | ||
| const normalizedRoot = root.endsWith(path.sep) ? root : root + path.sep; | ||
|
|
||
| while (lastIndex < len) { | ||
| let newlineIndex = output.indexOf('\n', lastIndex); | ||
| if (newlineIndex === -1) { | ||
| newlineIndex = len; | ||
| } | ||
|
|
||
| // Find start of trimmed substring | ||
| let start = lastIndex; | ||
| while (start < newlineIndex && output.charCodeAt(start) <= 32) { | ||
| start++; | ||
| } | ||
|
|
||
| // Find end of trimmed substring | ||
| let end = newlineIndex - 1; | ||
| while (end >= start && output.charCodeAt(end) <= 32) { | ||
| end--; | ||
| } | ||
|
|
||
| if (start <= end) { | ||
| const relativePath = output.slice(start, end + 1); | ||
|
Comment on lines
+72
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve leading and trailing spaces in file names. This loop trims all ASCII whitespace from each record, so a valid path like π‘ Proposed fix- // Find start of trimmed substring
- let start = lastIndex;
- while (start < newlineIndex && output.charCodeAt(start) <= 32) {
- start++;
- }
-
- // Find end of trimmed substring
- let end = newlineIndex - 1;
- while (end >= start && output.charCodeAt(end) <= 32) {
- end--;
- }
-
- if (start <= end) {
- const relativePath = output.slice(start, end + 1);
+ const start = lastIndex;
+ let end = newlineIndex;
+ if (end > start && output.charCodeAt(end - 1) === 13) {
+ end--;
+ }
+
+ if (start < end) {
+ const relativePath = output.slice(start, end);π€ Prompt for AI Agents |
||
|
|
||
| let fullPath = normalizedRoot + relativePath; | ||
| if (this.isWindows) { | ||
| filePath = filePath.toLowerCase(); | ||
| fullPath = fullPath.replace(/\//g, '\\').toLowerCase(); | ||
| } | ||
| set.add(filePath); | ||
|
|
||
| set.add(fullPath); | ||
| } | ||
|
|
||
| lastIndex = newlineIndex + 1; | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
π§© Analysis chain
π Script executed:
Repository: AhmmedSamier/DeepLens
Length of output: 107
π Script executed:
Repository: AhmmedSamier/DeepLens
Length of output: 1845
π Script executed:
Repository: AhmmedSamier/DeepLens
Length of output: 681
π Script executed:
Repository: AhmmedSamier/DeepLens
Length of output: 3707
π Script executed:
Repository: AhmmedSamier/DeepLens
Length of output: 685
π Script executed:
Repository: AhmmedSamier/DeepLens
Length of output: 2197
Normalize
rootto matchSearchEngine.normalizePath()behavior.The current code stores keys from raw
rootconcatenation without applyingpath.normalize(), whileSearchEnginenormalizes paths before lookups. IfworkspaceRootscontains mixed separators (e.g.,C:/repo\src), double separators (/tmp//repo), or non-native separators, the stored keys diverge from normalized lookup keys. This causesSearchScope.MODIFIEDfiltering to silently miss changed files.Proposed fix
Also applies to lines 87-89 where this normalized root is used to construct file paths.
π€ Prompt for AI Agents