Skip to content

⚡ Bolt: Remove intermediate allocations in normalize_search_text#609

Open
madmax983 wants to merge 1 commit into
trunkfrom
bolt-optimize-normalize-search-text-7326076267954398302
Open

⚡ Bolt: Remove intermediate allocations in normalize_search_text#609
madmax983 wants to merge 1 commit into
trunkfrom
bolt-optimize-normalize-search-text-7326076267954398302

Conversation

@madmax983
Copy link
Copy Markdown
Owner

💡 What: Rewrote normalize_search_text in src/skills.rs to construct the normalized string directly, avoiding intermediate String and Vec allocations, and fixed existing clippy warnings.
🎯 Why: .split_whitespace().collect::<Vec<_>>().join(" ") causes unnecessary heap allocations.
📊 Impact: Reduces memory allocations during skill indexing by building the normalized string in a single pre-allocated pass.
🔬 Measurement: Run cargo test and cargo bench.


PR created automatically by Jules for task 7326076267954398302 started by @madmax983

💡 What: Rewrote `normalize_search_text` in `src/skills.rs` to construct the normalized string directly, avoiding intermediate `String` and `Vec` allocations. Fixed existing clippy warnings.
🎯 Why: `.split_whitespace().collect::<Vec<_>>().join(" ")` causes unnecessary heap allocations.
📊 Impact: Reduces memory allocations during skill indexing by building the normalized string in a single pre-allocated pass.
🔬 Measurement: Run `cargo test --lib skills`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several optimizations and cleanups across the codebase. In src/run/swebench.rs, a socket read loop is simplified to a while let loop. In src/skills.rs, the normalize_search_text function is refactored to construct the normalized string in a single pass, eliminating intermediate allocations, and unit tests are added to verify its behavior. In src/stream/sweep_webhook.rs, timeout error matching is made more explicit, and a map().unwrap_or() chain is simplified to map_or(). The reviewer provided a valuable performance optimization suggestion for normalize_search_text to iterate over bytes instead of characters, which avoids UTF-8 decoding overhead for ASCII-only checks.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/skills.rs
Comment on lines 549 to 564
fn normalize_search_text(text: &str) -> String {
let mut out = String::with_capacity(text.len());
let mut in_word = false;
for ch in text.chars() {
if ch.is_ascii_alphanumeric() || ch == '$' || ch == '@' || ch == '/' {
if !in_word && !out.is_empty() {
out.push(' ');
}
out.push(ch.to_ascii_lowercase());
in_word = true;
} else {
out.push(' ');
in_word = false;
}
}
out.split_whitespace().collect::<Vec<_>>().join(" ")
out
}
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.

medium

The current implementation of normalize_search_text iterates over the characters of the input string using text.chars(). Since the allowed characters (is_ascii_alphanumeric, $, @, /) are all ASCII, any non-ASCII character or byte will naturally fall into the else branch and be treated as a word boundary.

By iterating over bytes using text.as_bytes() instead of text.chars(), we can completely avoid the overhead of UTF-8 decoding for the input string. This provides a significant performance boost, especially when processing large amounts of search text during indexing, while remaining fully safe and functionally identical.

Suggested change
fn normalize_search_text(text: &str) -> String {
let mut out = String::with_capacity(text.len());
let mut in_word = false;
for ch in text.chars() {
if ch.is_ascii_alphanumeric() || ch == '$' || ch == '@' || ch == '/' {
if !in_word && !out.is_empty() {
out.push(' ');
}
out.push(ch.to_ascii_lowercase());
in_word = true;
} else {
out.push(' ');
in_word = false;
}
}
out.split_whitespace().collect::<Vec<_>>().join(" ")
out
}
fn normalize_search_text(text: &str) -> String {
let mut out = String::with_capacity(text.len());
let mut in_word = false;
for &b in text.as_bytes() {
if b.is_ascii_alphanumeric() || b == b'$' || b == b'@' || b == b'/' {
if !in_word && !out.is_empty() {
out.push(' ');
}
out.push(b.to_ascii_lowercase() as char);
in_word = true;
} else {
in_word = false;
}
}
out
}

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.19%. Comparing base (9aa2ad9) to head (4543c67).

Files with missing lines Patch % Lines
src/stream/sweep_webhook.rs 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk     #609      +/-   ##
==========================================
- Coverage   85.19%   85.19%   -0.01%     
==========================================
  Files         114      114              
  Lines       65408    65418      +10     
==========================================
+ Hits        55725    55733       +8     
- Misses       9683     9685       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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