Skip to content

⚡ Bolt: Remove redundant String clones in redaction rules#623

Open
madmax983 wants to merge 1 commit into
trunkfrom
bolt-optimize-redaction-clones-14438193805074593971
Open

⚡ Bolt: Remove redundant String clones in redaction rules#623
madmax983 wants to merge 1 commit into
trunkfrom
bolt-optimize-redaction-clones-14438193805074593971

Conversation

@madmax983
Copy link
Copy Markdown
Owner

💡 What: Updated literal_index_map and literal_entries to use string slice references (&str) instead of owned String instances during the deduplication phase. Also added seen_literals.contains(&literal) checks to prevent cloning the literal string when the set already contains it.
🎯 Why: To prevent unnecessary heap allocations when iterating and deduplicating secret literals.
📊 Impact: Eliminates redundant .clone() calls, reducing memory allocations on the redaction initialization hot path.
🔬 Measurement: Verified correctness via cargo test --lib redaction.


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

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 optimizes string allocations in src/redaction.rs by storing &str references instead of owned Strings in literal_entries and literal_index_map, deferring cloning until necessary. A review comment correctly points out that the check seen_literals.contains(literal) is redundant because literal_entries is already deduplicated prior to the loop, making the lookup unnecessary.

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/redaction.rs
Comment on lines +184 to +187
if seen_literals.contains(literal) {
continue;
}
seen_literals.insert(literal.to_owned());
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

Since literal_entries is already deduplicated using literal_index_map (lines 171-182), all keys in literal_entries are guaranteed to be unique. Because seen_literals is empty before this loop and only populated within it, seen_literals.contains(literal) will always evaluate to false. Therefore, this check is redundant and can be safely removed to avoid unnecessary B-Tree lookups.

                seen_literals.insert(literal.to_owned());

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.40%. Comparing base (e98c81c) to head (0dd373a).

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk     #623   +/-   ##
=======================================
  Coverage   85.40%   85.40%           
=======================================
  Files         116      116           
  Lines       67035    67037    +2     
=======================================
+ Hits        57250    57253    +3     
+ Misses       9785     9784    -1     

☔ 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