Skip to content

⚡ Bolt: [performance improvement] Pre-compile regex in StringUtils.splitOnWhitespace - #618

Merged
LeanBitLab merged 1 commit into
mainfrom
bolt-optimize-splitonwhitespace-12438260748011971641
Oct 7, 2026
Merged

LeanBitLab merged 1 commit into
mainfrom
bolt-optimize-splitonwhitespace-12438260748011971641

Conversation

@LeanBitLab

Copy link
Copy Markdown
Owner

💡 What: Extract the whitespace split regex Regex("\\s+") inside StringUtils.splitOnWhitespace() into a private val file-level property.
🎯 Why: splitOnWhitespace() is an extension method called repeatedly in loops when managing dictionaries, evaluating math expression, suggesting emojis, etc. Allocating and compiling a regex instance on every single call creates unnecessary GC pressure and CPU overhead.
📊 Impact: Completely eliminates the cost of regex compilation across multiple critical code paths including settings searches and suggestion extraction, ensuring faster splits with zero allocation for the pattern itself.
🔬 Measurement: Verified that full testStandardDebugUnitTest passes. Repeated invocations will now use the pre-compiled WHITESPACE_REGEX static instance.


PR created automatically by Jules for task 12438260748011971641 started by @LeanBitLab

`StringUtils.splitOnWhitespace()` created a new `Regex("\\s+")` instance
every time it was called. Because it is used in various text processing
and dictionary-filtering paths, pre-compiling this to a single, static
property eliminates unnecessary regex compilation overhead and avoids
useless GC pressure during fast typing/searching.
@google-labs-jules

Copy link
Copy Markdown

👋 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.

@LeanBitLab
LeanBitLab merged commit db678c2 into main Oct 7, 2026
1 check passed
@LeanBitLab
LeanBitLab deleted the bolt-optimize-splitonwhitespace-12438260748011971641 branch October 7, 2026 12:07
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