Skip to content

⚡ Bolt: [O(1) FullName Property Early-Exit in Fuzzy Match]#519

Merged
AhmmedSamier merged 2 commits into
masterfrom
bolt-fullname-early-exit-17173473547880820362
Jun 28, 2026
Merged

⚡ Bolt: [O(1) FullName Property Early-Exit in Fuzzy Match]#519
AhmmedSamier merged 2 commits into
masterfrom
bolt-fullname-early-exit-17173473547880820362

Conversation

@AhmmedSamier

@AhmmedSamier AhmmedSamier commented Jun 19, 2026

Copy link
Copy Markdown
Owner

💡 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.


PR created automatically by Jules for task 17173473547880820362 started by @AhmmedSamier

Summary by CodeRabbit

  • Performance
    • Improved fuzzy search responsiveness by adding a quick eligibility check for full-name matching, avoiding unnecessary expensive scoring when the query can’t apply.
    • Search now precomputes additional flags during indexing so matching runs faster in the main search loop.
    • Overall, this reduces latency and speeds up results on larger datasets.

💡 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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds itemFullNameBitflags to SearchEngine, keeps it aligned across item lifecycle updates, uses it for an early-exit in tryFuzzyMatchFullName, updates benchmark JSON files, and adds a changelog note.

Changes

Search fullName Bitflags

Layer / File(s) Summary
itemFullNameBitflags lifecycle
language-server/src/core/search-engine.ts
Declares itemFullNameBitflags and keeps it aligned across set, add, truncate, move, clear, and cache-size paths.
Bitflag computation and storage
language-server/src/core/search-engine.ts
computeItemBitflags returns separate fullNameFlags, and prepareItemAtIndex stores them in itemFullNameBitflags.
Search early-exit and changelog
language-server/src/core/search-engine.ts, .jules/bolt.md
prepareSearchContext passes itemFullNameBitflags to the hot loop, tryFuzzyMatchFullName short-circuits on bitflag mismatch, and the changelog records the optimization.

Benchmark JSON Updates

Layer / File(s) Summary
Benchmark file shape updates
language-server/benchmarks/benchmarks.json, language-server/benchmarks/results_burst.json
benchmarks.json is reformatted without changing values, and results_burst.json is wrapped in a top-level array.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🐇 I hopped through flags and bytes so bright,
Full names now skip the costly flight.
If bits don’t match, away we go —
-Infinity first, then zippy snow! 🌨️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main performance optimization: an O(1) early-exit for fuzzy matching on fullName.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-fullname-early-exit-17173473547880820362

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.md

markdownlint-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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between fbf483d and adb9739.

📒 Files selected for processing (2)
  • .jules/bolt.md
  • language-server/src/core/search-engine.ts

Comment on lines 591 to 611
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 };
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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:

  1. fullNameFlags remains equal to nameFlags
  2. preparedFullNames[i] is set to null (from populateParallelArrays)

In tryFuzzyMatchFullName (lines 2026-2031):

  • The bitflag check (itemFullNameBitflags[i] & queryBitflags) === queryBitflags may pass if query characters are in the name
  • But then pFull is null, so the function returns -Infinity anyway

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.

Suggested change
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
@AhmmedSamier
AhmmedSamier merged commit f93f280 into master Jun 28, 2026
5 of 6 checks passed
@AhmmedSamier
AhmmedSamier deleted the bolt-fullname-early-exit-17173473547880820362 branch June 28, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant