Skip to content

⚡ Bolt: Path Bitflags for Fuzzy Matching Early-Exit#573

Closed
AhmmedSamier wants to merge 1 commit into
masterfrom
bolt/item-path-bitflags-3868954251576606181
Closed

⚡ Bolt: Path Bitflags for Fuzzy Matching Early-Exit#573
AhmmedSamier wants to merge 1 commit into
masterfrom
bolt/item-path-bitflags-3868954251576606181

Conversation

@AhmmedSamier

@AhmmedSamier AhmmedSamier commented Jul 14, 2026

Copy link
Copy Markdown
Owner

💡 What

Implemented an O(1) early-exit check in tryFuzzyMatchPath by tracking itemPathBitflags for relative file paths, parallel to existing name bitflags.

🎯 Why

When tryFuzzyMatchName and tryFuzzyMatchFullName fail to yield high scores, the search engine falls back to tryFuzzyMatchPath. Previously, this fallback unconditionally evaluated Fuzzysort.single(), which is expensive. If the query characters were present in the aggregate itemBitflags but not in the path itself, this resulted in wasted fuzzy sorting cycles.

📊 Impact

Measurably reduces the number of Fuzzysort.single() executions during deep fallback path matching, particularly for longer file paths and queries, dropping CPU overhead and GC pauses in the hot loop.

🔬 Measurement

Run bun run test in the language-server directory. Code paths have been verified via existing stream search and fuzzy matching regression tests. Benchmark improvements would be observed in large workspaces querying characters spread across different entity names that force fallback evaluations.


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

Summary by CodeRabbit

  • Performance
    • Improved search responsiveness by quickly skipping file paths that cannot match the query.
    • Reduced unnecessary fuzzy matching work, especially for searches across large project trees.

Introduces `itemPathBitflags` to the `SearchEngine`'s struct-of-arrays architecture to track character bitmasks specifically for relative file paths. This allows `tryFuzzyMatchPath` to bypass expensive `Fuzzysort.single()` evaluations when the required query characters are not present in the path string, avoiding wasted cycles when falling back to path matching.

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

SearchEngine now maintains per-item path bitflags derived from relative paths and uses them to skip impossible fuzzy path evaluations before invoking fuzzysort.

Changes

Path Bitflag Search Optimization

Layer / File(s) Summary
Compute and store path bitflags
language-server/src/core/search-engine.ts
computeItemBitflags derives pathFlags from each relative file path, includes them in aggregate flags, and stores them in itemPathBitflags.
Maintain parallel indexing state
language-server/src/core/search-engine.ts
Initialization, incremental additions, removals, moves, clearing, and cache sizing now maintain itemPathBitflags.
Apply the fuzzy path early exit
language-server/src/core/search-engine.ts, .jules/bolt.md
prepareSearchContext exposes path flags, and tryFuzzyMatchPath rejects paths whose flags do not contain the query characters before fuzzy scoring; the optimization is documented.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: google-labs-jules[bot], ahmedsamir3

🚥 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 describes the main change: adding path bitflags for fuzzy-matching early exit.
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/item-path-bitflags-3868954251576606181

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.

🧹 Nitpick comments (1)
language-server/src/core/search-engine.ts (1)

586-589: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Avoid object allocations in the indexing hot loop.

Returning an object from computeItemBitflags allocates memory for every item during setItems and addItems. Passing the index directly into the method to populate the parallel arrays eliminates this per-item allocation, reducing GC pressure and adhering to the indexing performance guidelines.

  • language-server/src/core/search-engine.ts#L586-L589: Replace the destructuring assignment with a direct call to the method, passing the index.
  • language-server/src/core/search-engine.ts#L603-L608: Change the method signature to accept index: number and return void.
  • language-server/src/core/search-engine.ts#L618-L622: Remove the return statement and assign the computed flags directly to the parallel arrays (this.itemNameBitflags[index] = nameFlags, etc.).
⚡ Proposed refactor
-    private prepareItemAtIndex(item: SearchableItem, index: number): void {
-        this.itemTypeIds[index] = TYPE_TO_ID[item.type];
-
-        const { nameFlags, fullNameFlags, pathFlags, aggregateFlags } = this.computeItemBitflags(item);
-        this.itemNameBitflags[index] = nameFlags;
-        this.itemFullNameBitflags[index] = fullNameFlags;
-        this.itemPathBitflags[index] = pathFlags;
-        this.itemBitflags[index] = aggregateFlags;
-        this.itemNameLengths[index] = item.name.length;
+    private prepareItemAtIndex(item: SearchableItem, index: number): void {
+        this.itemTypeIds[index] = TYPE_TO_ID[item.type];
+        
+        this.computeAndStoreItemBitflags(item, index);
+        this.itemNameLengths[index] = item.name.length;
-    private computeItemBitflags(item: SearchableItem): {
-        nameFlags: number;
-        fullNameFlags: number;
-        pathFlags: number;
-        aggregateFlags: number;
-    } {
+    private computeAndStoreItemBitflags(item: SearchableItem, index: number): void {
         if (item.relativeFilePath) {
             // Optimization: Skip normalization as calculateBitflags maps both \ and / to same bitflag (bit 30)
             pathFlags = this.calculateBitflags(item.relativeFilePath);
             aggregateFlags |= pathFlags;
         }
 
-        return { nameFlags, fullNameFlags, pathFlags, aggregateFlags };
+        this.itemNameBitflags[index] = nameFlags;
+        this.itemFullNameBitflags[index] = fullNameFlags;
+        this.itemPathBitflags[index] = pathFlags;
+        this.itemBitflags[index] = 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 586 - 589, Update
language-server/src/core/search-engine.ts#L586-L589 to replace the destructuring
assignment with a direct computeItemBitflags call that passes index. Change
computeItemBitflags at language-server/src/core/search-engine.ts#L603-L608 to
accept index: number and return void, then at
language-server/src/core/search-engine.ts#L618-L622 remove the returned object
and write nameFlags, fullNameFlags, pathFlags, and aggregateFlags directly into
the parallel arrays at index; apply these changes consistently for both setItems
and addItems callers.

Source: Coding guidelines

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

Nitpick comments:
In `@language-server/src/core/search-engine.ts`:
- Around line 586-589: Update
language-server/src/core/search-engine.ts#L586-L589 to replace the destructuring
assignment with a direct computeItemBitflags call that passes index. Change
computeItemBitflags at language-server/src/core/search-engine.ts#L603-L608 to
accept index: number and return void, then at
language-server/src/core/search-engine.ts#L618-L622 remove the returned object
and write nameFlags, fullNameFlags, pathFlags, and aggregateFlags directly into
the parallel arrays at index; apply these changes consistently for both setItems
and addItems callers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4432fe42-81ac-49b1-9544-f2f672078cde

📥 Commits

Reviewing files that changed from the base of the PR and between 124aa21 and 1cc0989.

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

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