Skip to content

⚡ Bolt: Add O(1) early-exit for path fuzzy matching#549

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

⚡ Bolt: Add O(1) early-exit for path fuzzy matching#549
AhmmedSamier wants to merge 1 commit into
masterfrom
bolt-path-early-exit-3706359694628607755

Conversation

@AhmmedSamier

@AhmmedSamier AhmmedSamier commented Jul 5, 2026

Copy link
Copy Markdown
Owner

💡 What: Added an itemPathBitflags parallel array to the SearchEngine class to perform an O(1) early-exit check in tryFuzzyMatchPath.
🎯 Why: Because the overall itemBitflags aggregate can pass due to a match within name or fullName, it does not guarantee that the relativeFilePath contains the target characters. Without this check, falling back to tryFuzzyMatchPath triggers an expensive string evaluation using Fuzzysort.single() unconditionally, leading to wasted cycles on impossible matches.
📊 Impact: Speeds up fallback fuzzy matching in hot loops by entirely skipping expensive string operations for items where the path string doesn't contain all query characters.
🔬 Measurement: Verify by executing cd language-server && bun run test successfully with the new implementation without regressions, and observing benchmark durations during rapid typing if available.


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

Summary by CodeRabbit

  • Bug Fixes

    • Improved fuzzy search responsiveness by skipping unnecessary path matching when the query can’t match the file path.
    • Search results should feel faster, especially in large workspaces.
  • Documentation

    • Added a note describing the search optimization approach for future reference.

Added `itemPathBitflags` parallel array to the `SearchEngine` class to allow for O(1) early exit when checking `tryFuzzyMatchPath`. By skipping the expensive `Fuzzysort.single()` string operations for paths that do not even contain all the queried characters, fallback search performance is significantly improved.

Includes necessary lifecycle array management operations (`ensureCapacity`, `setItems`, `addItems`, `truncateArrays`, `moveItem`, `clear`, and memory calculation).

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

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new itemPathBitflags parallel Uint32Array to SearchEngine for tracking character presence in each item's relativeFilePath, computed in computeItemBitflags and maintained across all array lifecycle operations (allocation, resize, clear, truncate, move). Uses it for an O(1) early-exit check in tryFuzzyMatchPath before invoking Fuzzysort.single(). Adds a corresponding documentation entry.

Changes

Path Bitflag Early-Exit Optimization

Layer / File(s) Summary
Bitflag computation
language-server/src/core/search-engine.ts
Declares itemPathBitflags field; computeItemBitflags computes pathFlags from relativeFilePath, ORs into aggregateFlags, and prepareItemAtIndex stores it.
Parallel array lifecycle maintenance
language-server/src/core/search-engine.ts
Synchronizes itemPathBitflags allocation/resizing in setItems and addItems, resets it in clear, truncates/moves it in truncateArrays/moveItem, and includes it in getCacheSize.
Search hot-path early-exit
language-server/src/core/search-engine.ts, .jules/bolt.md
Exposes itemPathBitflags via prepareSearchContext, adds an early-exit bitflag guard in tryFuzzyMatchPath to skip Fuzzysort.single(), and documents the pattern.

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

Possibly related PRs

  • AhmmedSamier/DeepLens#256: Same file introduces analogous O(1) bitflag early-exit logic to skip Fuzzysort work in the scoring loop.
  • AhmmedSamier/DeepLens#519: Same file adds the analogous bitflag precheck and early-exit pattern for fullName via tryFuzzyMatchFullName.
  • AhmmedSamier/DeepLens#503: Same file applies the identical bitflag early-exit pattern to tryFuzzyMatchName via itemNameBitflags.

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 optimization: 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-early-exit-3706359694628607755

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 @.jules/bolt.md:
- Line 99: The changelog entry date is out of chronological order in the
markdown history list. Update the date in the affected entry so it matches the
surrounding 2026 entries and preserves descending order in the .jules/bolt.md
timeline, using the nearby "2026-08-05" entry and the current heading text as
the reference point.
🪄 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: 048020b0-3d5f-46e5-a31f-d78a671c0893

📥 Commits

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

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

Comment thread .jules/bolt.md
## 2026-10-27 - [Fast Endpoint Matching Bypass]
**Learning:** In the `SearchEngine.processItemForSearch` method, `tryUrlEndpointMatch` was previously called for all items that passed the bitflag check or were preserved for URL evaluation, regardless of whether the item was actually an endpoint. This added unnecessary function call overhead and duplicate condition evaluations for non-endpoint items.
**Action:** Add an explicit O(1) `typeId === 11 /* ENDPOINT */` check alongside `context.isPotentialUrl` directly inside `processItemForSearch` to completely bypass the `tryUrlEndpointMatch` function call for all non-endpoint items. This eliminates redundant evaluations and speeds up the fallback search path.
## 2025-05-25 - [O(1) Path Property Early-Exit in Fuzzy Match]

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Entry date appears to be a typo / out of chronological order.

This entry is inserted after the 2026-08-05 entry but is dated 2025-05-25, breaking the file's chronological ordering. Given the other recent entries are dated 2026, this likely should be a 2026 date.

📝 Suggested date correction
-## 2025-05-25 - [O(1) Path Property Early-Exit in Fuzzy Match]
+## 2026-08-06 - [O(1) Path Property Early-Exit in Fuzzy Match]
📝 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
## 2025-05-25 - [O(1) Path Property Early-Exit in Fuzzy Match]
## 2026-08-06 - [O(1) Path Property Early-Exit in Fuzzy Match]
🤖 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 @.jules/bolt.md at line 99, The changelog entry date is out of chronological
order in the markdown history list. Update the date in the affected entry so it
matches the surrounding 2026 entries and preserves descending order in the
.jules/bolt.md timeline, using the nearby "2026-08-05" entry and the current
heading text as the reference point.

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