⚡ Bolt: [O(1) FullName Property Early-Exit in Fuzzy Match]#519
Conversation
💡 What: Introduced a dedicated `itemFullNameBitflags` array in the `SearchEngine` to store character bitmasks specific to the `fullName` property. Used this to implement an O(1) bitflag early-exit check inside `tryFuzzyMatchFullName` before executing `Fuzzysort.single()`. 🎯 Why: The fallback fuzzy match method `tryFuzzyMatchFullName` evaluated items using expensive string-matching logic without verifying if the required characters were actually present in the `fullName` itself. This was problematic because the aggregate `itemBitflags` check could pass when characters were spread entirely across the file path, leading to wasted CPU cycles when processing `fullName`. 📊 Impact: Significantly reduces unnecessary function calls and string operations (`Fuzzysort.single()`) during fuzzy fallback passes, lowering CPU execution latency during complex queries or path-dependent matching scenarios. 🔬 Measurement: Validated via the existing `./run_benchmarks.sh` pipeline, showing consistent speedups in the "Fuzzy Search" and "Route Match Search" workloads without regressions. Co-authored-by: AhmmedSamier <17784876+AhmmedSamier@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdds ChangesSearch fullName Bitflags
Benchmark JSON Updates
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 markdownlint-cli2 (0.22.1).jules/bolt.mdmarkdownlint-cli2 wrapper config was not available before execution Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@language-server/src/core/search-engine.ts`:
- Around line 591-611: In the `computeItemBitflags` method, change the
initialization of the `fullNameFlags` variable from being set to `nameFlags` to
being initialized to 0. This ensures that when an item does not have a distinct
fullName (when `shouldProcessFullName` returns false), the fullNameFlags bitflag
will be 0, allowing the bitflag check in `tryFuzzyMatchFullName` to exit early
instead of performing unnecessary bitwise AND operations on items that cannot
match anyway.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d7b974c7-5db5-439a-92a6-813bf68b2259
📒 Files selected for processing (2)
.jules/bolt.mdlanguage-server/src/core/search-engine.ts
| private computeItemBitflags(item: SearchableItem): { | ||
| nameFlags: number; | ||
| fullNameFlags: number; | ||
| aggregateFlags: number; | ||
| } { | ||
| const nameFlags = this.calculateBitflags(item.name); | ||
| let aggregateFlags = nameFlags; | ||
| let fullNameFlags = nameFlags; | ||
|
|
||
| if (this.shouldProcessFullName(item) && item.fullName) { | ||
| aggregateFlags |= this.calculateBitflags(item.fullName); | ||
| fullNameFlags = this.calculateBitflags(item.fullName); | ||
| aggregateFlags |= fullNameFlags; | ||
| } | ||
|
|
||
| if (item.relativeFilePath) { | ||
| // Optimization: Skip normalization as calculateBitflags maps both \ and / to same bitflag (bit 30) | ||
| aggregateFlags |= this.calculateBitflags(item.relativeFilePath); | ||
| } | ||
|
|
||
| return { nameFlags, aggregateFlags }; | ||
| return { nameFlags, fullNameFlags, aggregateFlags }; | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Initialize fullNameFlags to 0 instead of nameFlags for better early-exit.
The current implementation sets fullNameFlags = nameFlags on line 598. When an item has no distinct fullName (shouldProcessFullName returns false), this causes:
fullNameFlagsremains equal tonameFlagspreparedFullNames[i]is set tonull(frompopulateParallelArrays)
In tryFuzzyMatchFullName (lines 2026-2031):
- The bitflag check
(itemFullNameBitflags[i] & queryBitflags) === queryBitflagsmay pass if query characters are in the name - But then
pFullis null, so the function returns-Infinityanyway
This defeats the purpose of the bitflag early-exit: we're performing an unnecessary bitflag AND operation for items that will never match because they lack a distinct fullName.
⚡ Proposed fix to eliminate unnecessary bitflag checks
private computeItemBitflags(item: SearchableItem): {
nameFlags: number;
fullNameFlags: number;
aggregateFlags: number;
} {
const nameFlags = this.calculateBitflags(item.name);
let aggregateFlags = nameFlags;
- let fullNameFlags = nameFlags;
+ let fullNameFlags = 0;
if (this.shouldProcessFullName(item) && item.fullName) {
fullNameFlags = this.calculateBitflags(item.fullName);
aggregateFlags |= fullNameFlags;
}
if (item.relativeFilePath) {
// Optimization: Skip normalization as calculateBitflags maps both \ and / to same bitflag (bit 30)
aggregateFlags |= this.calculateBitflags(item.relativeFilePath);
}
return { nameFlags, fullNameFlags, aggregateFlags };
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| private computeItemBitflags(item: SearchableItem): { | |
| nameFlags: number; | |
| fullNameFlags: number; | |
| aggregateFlags: number; | |
| } { | |
| const nameFlags = this.calculateBitflags(item.name); | |
| let aggregateFlags = nameFlags; | |
| let fullNameFlags = nameFlags; | |
| if (this.shouldProcessFullName(item) && item.fullName) { | |
| aggregateFlags |= this.calculateBitflags(item.fullName); | |
| fullNameFlags = this.calculateBitflags(item.fullName); | |
| aggregateFlags |= fullNameFlags; | |
| } | |
| if (item.relativeFilePath) { | |
| // Optimization: Skip normalization as calculateBitflags maps both \ and / to same bitflag (bit 30) | |
| aggregateFlags |= this.calculateBitflags(item.relativeFilePath); | |
| } | |
| return { nameFlags, aggregateFlags }; | |
| return { nameFlags, fullNameFlags, aggregateFlags }; | |
| } | |
| private computeItemBitflags(item: SearchableItem): { | |
| nameFlags: number; | |
| fullNameFlags: number; | |
| aggregateFlags: number; | |
| } { | |
| const nameFlags = this.calculateBitflags(item.name); | |
| let aggregateFlags = nameFlags; | |
| let fullNameFlags = 0; | |
| if (this.shouldProcessFullName(item) && item.fullName) { | |
| fullNameFlags = this.calculateBitflags(item.fullName); | |
| aggregateFlags |= fullNameFlags; | |
| } | |
| if (item.relativeFilePath) { | |
| // Optimization: Skip normalization as calculateBitflags maps both \ and / to same bitflag (bit 30) | |
| aggregateFlags |= this.calculateBitflags(item.relativeFilePath); | |
| } | |
| return { nameFlags, fullNameFlags, aggregateFlags }; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@language-server/src/core/search-engine.ts` around lines 591 - 611, In the
`computeItemBitflags` method, change the initialization of the `fullNameFlags`
variable from being set to `nameFlags` to being initialized to 0. This ensures
that when an item does not have a distinct fullName (when
`shouldProcessFullName` returns false), the fullNameFlags bitflag will be 0,
allowing the bitflag check in `tryFuzzyMatchFullName` to exit early instead of
performing unnecessary bitwise AND operations on items that cannot match anyway.
💘 Generated with Crush Assisted-by: Crush:deepseek-v4-flash-free
💡 What:
Introduced a dedicated
itemFullNameBitflagsarray in theSearchEngineto store character bitmasks specific to thefullNameproperty. Used this to implement an O(1) bitflag early-exit check insidetryFuzzyMatchFullNamebefore executingFuzzysort.single().🎯 Why:
The fallback fuzzy match method
tryFuzzyMatchFullNameevaluated items using expensive string-matching logic without verifying if the required characters were actually present in thefullNameitself. This was problematic because the aggregateitemBitflagscheck could pass when characters were spread entirely across the file path, leading to wasted CPU cycles when processingfullName.📊 Impact:
Significantly reduces unnecessary function calls and string operations (
Fuzzysort.single()) during fuzzy fallback passes, lowering CPU execution latency during complex queries or path-dependent matching scenarios.🔬 Measurement:
Validated via the existing
./run_benchmarks.shpipeline, showing consistent speedups in the "Fuzzy Search" and "Route Match Search" workloads without regressions.PR created automatically by Jules for task 17173473547880820362 started by @AhmmedSamier
Summary by CodeRabbit