Skip to content

⚡ Bolt: [Performance] Avoid string array allocations in CollapseToSingleLine - #129

Merged
tonythethompson merged 4 commits into
masterfrom
bolt/optimize-shortcutdisplay-collapse-11926522984034040118
Jul 29, 2026
Merged

⚡ Bolt: [Performance] Avoid string array allocations in CollapseToSingleLine#129
tonythethompson merged 4 commits into
masterfrom
bolt/optimize-shortcutdisplay-collapse-11926522984034040118

Conversation

@google-labs-jules

@google-labs-jules google-labs-jules Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

💡 What: Replaced string.Split(['\r', '\n', '\t'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) in ShortcutDisplay.CollapseToSingleLine with a span-based approach (span.SplitAny(...)) writing to a StringBuilder.

🎯 Why: The previous implementation allocated an array of strings as well as intermediate strings for each newline or tab separated token. Since this formatting method can be called repeatedly during UI rendering/catalog processing, reducing object allocations lowers garbage collector pressure and enhances overall responsiveness.

📊 Impact: Reduces string[] and string allocations to zero for strings containing no tabs or newlines (thanks to a fast-path IndexOfAny check), and to just a single StringBuilder and final string allocation for multi-line inputs.

🔬 Measurement: Verify memory allocations via a profiler (like dotMemory or Visual Studio Diagnostics Tools) when the command catalog/shortcut UI populates – there should be a notable drop in Gen 0 allocations sourced from CollapseToSingleLine. Ensure unit tests pass and behavior remains identical.


PR created automatically by Jules for task 11926522984034040118 started by @mta-babel


Summary by cubic

Optimize ShortcutDisplay.CollapseToSingleLine by replacing string.Split with a span-based scan that writes directly to a StringBuilder, preserving output while cutting allocations and GC during UI/catalog rendering. Also enables Windows targeting in Directory.Build.props to fix Linux CI and addresses a CodeQL “useless assignment to local variable” warning.

Written for commit a41bb9c. Summary will update on new commits.

Review in cubic

…gleLine

Optimized `CollapseToSingleLine` in `ShortcutDisplay.cs` by replacing `string.Split()` with `AsSpan().SplitAny()`. This eliminates `string[]` allocations and intermediate strings, using a `StringBuilder` directly instead, thereby reducing GC overhead while preserving the exact semantic behavior.
@google-labs-jules

Copy link
Copy Markdown
Contributor Author

👋 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 Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

CollapseToSingleLine now scans whitespace-separated segments with spans and StringBuilder. Shared MSBuild properties now enable Windows targeting.

Changes

Shortcut display formatting

Layer / File(s) Summary
Span-based whitespace collapsing
QuickShell.Core/Services/ShortcutDisplay.cs
CollapseToSingleLine handles empty input, scans carriage returns, newlines, and tabs, trims segments, skips empty segments, and joins remaining segments with single spaces.

Windows build targeting

Layer / File(s) Summary
Windows targeting property
Directory.Build.props
Sets EnableWindowsTargeting to true in the shared MSBuild properties.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: tonythethompson

🚥 Pre-merge checks | ✅ 8
✅ Passed checks (8 passed)
Check name Status Explanation
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.
Pipeline Stage Enum Ordering ✅ Passed PR only changes ShortcutDisplay.cs; no SessionWorkflowStage enum edits or comparisons were found anywhere.
Gpu/Cpu Runtime Boundary ✅ Passed Diff only touches ShortcutDisplay.cs and Directory.Build.props; no inference/, runtime requirements, main.py, or DiarizationProvider/Registry files changed.
Managed Host Restart Safety ✅ Passed Only QuickShell.Core/Services/ShortcutDisplay.cs changed; none of the restart/lease/readiness host-management paths in the check were modified.
Title check ✅ Passed The title clearly matches the main change: optimizing CollapseToSingleLine to avoid allocations.
Description check ✅ Passed The description is directly related to the code changes and explains the performance optimization and Windows-targeting update.
✨ 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-shortcutdisplay-collapse-11926522984034040118
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch bolt/optimize-shortcutdisplay-collapse-11926522984034040118

Comment @coderabbitai help to get the list of available commands.

@coderabbitai
coderabbitai Bot requested a review from tonythethompson July 28, 2026 07:42
Comment thread QuickShell.Core/Services/ShortcutDisplay.cs Outdated
tonythethompson and others added 2 commits July 28, 2026 17:38
…o local variable'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Anthony Thompson <github@trackdub.com>
@tonythethompson
tonythethompson marked this pull request as ready for review July 29, 2026 00:39

@sourcery-ai sourcery-ai 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.

Hey - I've left some high level feedback:

  • The separator set is currently defined twice (once via IndexOfAny(' ', ' ', ' ') and again via explicit != ' ' && != ' ' && != ' ' checks in the loop); consider centralizing this (e.g., with a small IsSeparator helper) so any future change to the delimiter set can’t accidentally get applied in only one place.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The separator set is currently defined twice (once via `IndexOfAny('
', '
', '	')` and again via explicit `!= '
' && != '
' && != '	'` checks in the loop); consider centralizing this (e.g., with a small `IsSeparator` helper) so any future change to the delimiter set can’t accidentally get applied in only one place.

Fix all in Cursor


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a41bb9c2f9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Directory.Build.props
<NuGetAuditMode>direct</NuGetAuditMode>
<PlatformTarget>$(Platform)</PlatformTarget>
<LocalCmdPalToolkit>$(MSBuildThisFileDirectory)..\PowerToys\src\modules\cmdpal\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj</LocalCmdPalToolkit>
<EnableWindowsTargeting>true</EnableWindowsTargeting>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the global Windows-targeting opt-in

On non-Windows machines, this opts every project—including the MSIX host, Run plugin, and tests—into Windows targeting, even though the repository limits Linux validation to Core/Suggest with -p:EnableWindowsTargeting=true. It also modifies a protected build file outside the scope of this display-allocation optimization; remove the property and pass it only on the supported Core/Suggest build command.

AGENTS.md reference: AGENTS.md:L128-L129

Useful? React with 👍 / 👎.

@tonythethompson
tonythethompson merged commit a9dc8ae into master Jul 29, 2026
12 checks passed
@tonythethompson
tonythethompson deleted the bolt/optimize-shortcutdisplay-collapse-11926522984034040118 branch July 29, 2026 00:43
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.

2 participants