Skip to content

⚡ Bolt: O(1) early-exit for path property fuzzy matching#552

Closed
AhmmedSamier wants to merge 1 commit into
masterfrom
bolt-path-bitflag-early-exit-2437337519263861253
Closed

⚡ Bolt: O(1) early-exit for path property fuzzy matching#552
AhmmedSamier wants to merge 1 commit into
masterfrom
bolt-path-bitflag-early-exit-2437337519263861253

Conversation

@AhmmedSamier

@AhmmedSamier AhmmedSamier commented Jul 6, 2026

Copy link
Copy Markdown
Owner

💡 What: Added an itemPathBitflags parallel array and an O(1) bitflag early-exit check to tryFuzzyMatchPath.
🎯 Why: To prevent executing expensive Fuzzysort.single() string operations on the file path when the required characters are missing from the path itself (e.g., they matched due to the name or fullName properties during the aggregate bitflag check).
📊 Impact: Significant reduction in CPU cycles and wasted string evaluations during the fallback fuzzy search path, especially for queries that happen to match scattered characters in the item's name but not its path.
🔬 Measurement: Run a burst search with patterns that heavily rely on path filtering. Profiling will show a reduction in time spent inside tryFuzzyMatchPath and Fuzzysort.single.


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

Summary by CodeRabbit

  • Performance Improvements
    • Faster fuzzy path matching with an early-exit check that skips unnecessary search work when a path cannot match.
    • Improved search responsiveness for items matched by relative file path, especially in larger result sets.

Added `itemPathBitflags` parallel array to the `SearchEngine` to track bitflags specifically for file paths. This allows for an O(1) early-exit check in `tryFuzzyMatchPath`, preventing expensive `Fuzzysort.single()` evaluations when query characters are spread across other item fields (name/fullName) but not present in the relative file path. Updated all array lifecycle methods and documented the learning in the performance journal.

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 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 46669254-02c1-4434-a826-5220b37393e4

📥 Commits

Reviewing files that changed from the base of the PR and between 124aa21 and 853c654.

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

📝 Walkthrough

Walkthrough

Adds a new parallel itemPathBitflags typed array to SearchEngine, computed from relativeFilePath during item preparation and maintained through allocation, resizing, truncation, compaction, and clearing. tryFuzzyMatchPath uses it for an O(1) early-exit before running Fuzzysort. A learnings log entry documents the change.

Changes

Path Bitflag Early-Exit Feature

Layer / File(s) Summary
Bitflag computation and storage
language-server/src/core/search-engine.ts
computeItemBitflags computes pathFlags from relativeFilePath and ORs it into aggregate flags; prepareItemAtIndex stores the result into itemPathBitflags.
Array lifecycle management
language-server/src/core/search-engine.ts
New itemPathBitflags field is allocated in setItems, resized/copied in addItems, sliced in truncateArrays, compacted in moveItem, and reset in clear.
Search context wiring and early-exit usage
language-server/src/core/search-engine.ts, .jules/bolt.md
prepareSearchContext passes itemPathBitflags into the hot loop, tryFuzzyMatchPath gates on it before calling Fuzzysort, getCacheSize reports its byte size, and a learnings entry documents the optimization.

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

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant SearchEngine
  participant tryFuzzyMatchPath
  participant Fuzzysort

  Caller->>SearchEngine: prepareSearchContext(query)
  SearchEngine-->>tryFuzzyMatchPath: pass itemPathBitflags, queryBitflags
  loop for each item i
    tryFuzzyMatchPath->>tryFuzzyMatchPath: check (itemPathBitflags[i] & queryBitflags) !== queryBitflags
    alt bitflags mismatch
      tryFuzzyMatchPath-->>SearchEngine: reject early (no match)
    else bitflags match
      tryFuzzyMatchPath->>Fuzzysort: single(query, path)
      Fuzzysort-->>tryFuzzyMatchPath: match result
      tryFuzzyMatchPath-->>SearchEngine: return match result
    end
  end
Loading

Possibly related PRs

  • AhmmedSamier/DeepLens#519: Both extend the computeItemBitflags/prepareSearchContext pipeline with a new parallel bitflag buffer for O(1) early-exit before Fuzzysort, this PR for relativeFilePath, the other for fullName.
  • AhmmedSamier/DeepLens#521: Both add a new parallel per-item bitflag array wired through computeItemBitflags/prepareItemAtIndex into a fuzzy match function's feasibility check.
  • AhmmedSamier/DeepLens#480: Both modify the search hot loop to add or relocate O(1) bitflag-based early rejection of candidates in search-engine.ts.

Suggested labels: codex

🚥 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 change: an O(1) early-exit for path fuzzy matching.
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-path-bitflag-early-exit-2437337519263861253

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.

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