Skip to content

⚡ Bolt: optimize technology detection path checks and allocations#459

Draft
yacosta738 wants to merge 1 commit into
mainfrom
bolt-optimize-tech-detection-v2-1553060984072360262
Draft

⚡ Bolt: optimize technology detection path checks and allocations#459
yacosta738 wants to merge 1 commit into
mainfrom
bolt-optimize-tech-detection-v2-1553060984072360262

Conversation

@yacosta738

Copy link
Copy Markdown
Contributor

⚡ Bolt: optimize technology detection path checks and allocations

💡 What:

  • Refactored CompiledConfigFileContentRules to store pre-compiled PathBufs instead of Strings.
  • Implemented depth-aware existence checks leveraging MAX_DISCOVER_DEPTH.
  • Minimized allocations in gather_content_scan_files using Path::new.

🎯 Why:
The technology detection system evaluates over 111 technologies. Many rules specify shallow configuration markers (like package.json or Cargo.toml). Previously, the system was performing redundant fs::exists syscalls for these markers even though they were already present in the metadata.paths cache (which covers all files up to depth 4). Additionally, storing markers as String forced a new PathBuf allocation for every rule evaluation.

📊 Impact:

  • Eliminates hundreds of redundant fs::exists syscalls per detection run.
  • Reduces heap pressure by moving PathBuf allocations from the hot loop (evaluation) to the cold path (rule compilation).

🔬 Measurement:

  • Verified via full test suite (cargo test --all-features).
  • Correctness confirmed by manual inspection of metadata.paths population logic.

PR created automatically by Jules for task 1553060984072360262 started by @yacosta738

- Refactor `CompiledConfigFileContentRules` to store pre-compiled `PathBuf`s instead of `String`s, eliminating repeated heap allocations during rule evaluation.
- Implement depth-aware existence checks using `MAX_DISCOVER_DEPTH` (4) to skip redundant `fs::exists` syscalls for shallow paths already indexed in `metadata.paths`.
- Optimize Gradle layout checks in `gather_content_scan_files` to use `Path::new` for existence testing.
- These changes significantly reduce the CPU and I/O overhead of technology detection, especially in projects with complex catalog rules.
@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 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Performance

    • Enhanced project detection efficiency through optimized file-checking logic and improved caching mechanisms.
  • Refactor

    • Improved internal detection structure to reduce redundant operations.

Walkthrough

Optimizes technology detection by pre-compiling file path markers into PathBuf during rule initialization and replacing filesystem calls with metadata-backed path checks that fall back to filesystem existence only for deep paths, reducing redundant syscalls during discovery.

Changes

Technology Detection Performance Optimization

Layer / File(s) Summary
Config rule compilation and type contract
src/skills/detect.rs
CompiledConfigFileContentRules.files type changes from Vec<String> to Vec<PathBuf>, and rule compilation converts configured file paths into PathBuf values for reuse.
Detection with depth-aware metadata checks
src/skills/detect.rs
Config file and content file detection now prefer metadata.paths.contains(...) and fall back to filesystem exists() only when path component depth exceeds MAX_DISCOVER_DEPTH. Applied across config_files, Gradle layout discovery, explicit content files, and workspace expansion patterns.
Optimization journal entry
.agents/journal/bolt.md
Documents the performance optimization: depth-aware metadata caching to avoid redundant filesystem syscalls, and pre-compiled PathBuf markers initialized once instead of per-evaluation in the hot loop.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit's verse on paths optimized,
String-to-PathBuf, cleverly prized,
Deep check the metadata, cached and true,
Filesystem only when needed—phew!
Fast tech detection, the burrow's delight! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly summarizes the main change: optimizing technology detection path checks and allocations, which aligns with the core refactoring work shown in the changeset.
Description check ✅ Passed The description is thoroughly related to the changeset, detailing specific optimizations made to CompiledConfigFileContentRules, depth-aware checks, and allocation reductions that match the file summaries.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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-optimize-tech-detection-v2-1553060984072360262

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 and usage tips.

@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 @.agents/journal/bolt.md:
- Line 172: The journal contains year typos in the section headings: update the
heading "## 2025-05-27 - Depth-Aware Existence Checks and Rule Pre-Compilation"
to "## 2026-05-27" (keeping the rest of the title) and also fix the earlier
heading "## 2025-05-24" to "## 2026-05-24" so all dates align with the
surrounding 2026 entries; edit the markdown headings in .agents/journal/bolt.md
accordingly.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9e6b5554-6450-4482-b5d6-71aa8198f30f

📥 Commits

Reviewing files that changed from the base of the PR and between 0b6536f and 46383be.

📒 Files selected for processing (2)
  • .agents/journal/bolt.md
  • src/skills/detect.rs

Comment thread .agents/journal/bolt.md
**Action:** Prefer iterator-based pattern matching over `Vec` collection when processing large numbers
of items in a loop. Use `Clone` bounds on iterators to support backtracking without re-allocation.

## 2025-05-27 - Depth-Aware Existence Checks and Rule Pre-Compilation

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Correct the journal entry date.

The entry is dated 2025-05-27, but the PR was created on 2026-06-11. Given the chronological context of surrounding entries (2026-05-20, 2026-05-21, 2026-05-22) and that the current date is June 2026, this should be 2026-05-27.

Additionally, line 163 shows ## 2025-05-24 which also appears to be a year typo and should likely be 2026-05-24.

📅 Proposed fix for date consistency
-## 2025-05-27 - Depth-Aware Existence Checks and Rule Pre-Compilation
+## 2026-05-27 - Depth-Aware Existence Checks and Rule Pre-Compilation

And for line 163:

-## 2025-05-24 - Allocation-Free Path Glob Matching
+## 2026-05-24 - Allocation-Free Path Glob Matching
📝 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-27 - Depth-Aware Existence Checks and Rule Pre-Compilation
## 2026-05-27 - Depth-Aware Existence Checks and Rule Pre-Compilation
🤖 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 @.agents/journal/bolt.md at line 172, The journal contains year typos in the
section headings: update the heading "## 2025-05-27 - Depth-Aware Existence
Checks and Rule Pre-Compilation" to "## 2026-05-27" (keeping the rest of the
title) and also fix the earlier heading "## 2025-05-24" to "## 2026-05-24" so
all dates align with the surrounding 2026 entries; edit the markdown headings in
.agents/journal/bolt.md accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant