From b3a86a49ed998cd6b0349a0c5f04b15231d10108 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 26 Jul 2026 07:33:29 +0000 Subject: [PATCH 1/5] Optimize string parsing to eliminate array allocations Replaced string.Split with AsSpan().Split and IndexOfAny to avoid unnecessary string array allocations and reduce GC pressure. --- .../Services/LaunchCommandSanity.cs | 24 ++++++++++++++----- .../Services/WorkspaceHealthCheck.cs | 5 +++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/QuickShell.Core/Services/LaunchCommandSanity.cs b/QuickShell.Core/Services/LaunchCommandSanity.cs index 091172b7..9fdc6ac2 100644 --- a/QuickShell.Core/Services/LaunchCommandSanity.cs +++ b/QuickShell.Core/Services/LaunchCommandSanity.cs @@ -68,17 +68,29 @@ public static bool IsUsableDotNetProjectFileName(string? fileName) private static bool LooksLikeTempProjectReference(string command) { // e.g. dotnet watch --project tmp_serilog_probe.csproj - foreach (var token in command.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)) + // Bolt: Performance optimization - use command.AsSpan().Split(' ') to avoid string array allocations + var commandSpan = command.AsSpan(); + foreach (var range in commandSpan.Split(' ')) { - var file = token.Trim('"', '\''); - if (!file.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) - && !file.EndsWith(".fsproj", StringComparison.OrdinalIgnoreCase) - && !file.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) - && !file.EndsWith(".slnx", StringComparison.OrdinalIgnoreCase)) + var tokenSpan = commandSpan[range].Trim(); + if (tokenSpan.IsEmpty) { continue; } + var fileSpan = tokenSpan.Trim(['"', '\'']); + + // Check extensions using spans to avoid allocations + if (!fileSpan.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) + && !fileSpan.EndsWith(".fsproj", StringComparison.OrdinalIgnoreCase) + && !fileSpan.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) + && !fileSpan.EndsWith(".slnx", StringComparison.OrdinalIgnoreCase)) + { + continue; + } + + // Fall back to string allocation only when necessary to call IsUsableDotNetProjectFileName + var file = fileSpan.ToString(); if (!IsUsableDotNetProjectFileName(file)) { return true; diff --git a/QuickShell.Core/Services/WorkspaceHealthCheck.cs b/QuickShell.Core/Services/WorkspaceHealthCheck.cs index 1e91aeab..efe08ac2 100644 --- a/QuickShell.Core/Services/WorkspaceHealthCheck.cs +++ b/QuickShell.Core/Services/WorkspaceHealthCheck.cs @@ -562,7 +562,10 @@ private static IEnumerable DetectPorts(TerminalShortcut shortcut) return endQuote > 1 ? Path.GetFileName(trimmed[1..endQuote]) : null; } - var token = trimmed.Split([' ', '\t'], StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); + // Bolt: Performance optimization - use IndexOfAny to avoid string array allocation from Split + var spaceIndex = trimmed.AsSpan().IndexOfAny(' ', '\t'); + var token = spaceIndex >= 0 ? trimmed[..spaceIndex] : trimmed; + if (string.IsNullOrWhiteSpace(token)) { return null; From 691d6659c6ac8c07093ec744e3e1efbb3649cbbe Mon Sep 17 00:00:00 2001 From: Anthony Thompson Date: Sun, 26 Jul 2026 02:54:31 -0700 Subject: [PATCH 2/5] Update QuickShell.Core/Services/WorkspaceHealthCheck.cs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Anthony Thompson --- QuickShell.Core/Services/WorkspaceHealthCheck.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/QuickShell.Core/Services/WorkspaceHealthCheck.cs b/QuickShell.Core/Services/WorkspaceHealthCheck.cs index efe08ac2..3004117f 100644 --- a/QuickShell.Core/Services/WorkspaceHealthCheck.cs +++ b/QuickShell.Core/Services/WorkspaceHealthCheck.cs @@ -564,8 +564,7 @@ private static IEnumerable DetectPorts(TerminalShortcut shortcut) // Bolt: Performance optimization - use IndexOfAny to avoid string array allocation from Split var spaceIndex = trimmed.AsSpan().IndexOfAny(' ', '\t'); - var token = spaceIndex >= 0 ? trimmed[..spaceIndex] : trimmed; - + var token = (spaceIndex >= 0 ? trimmed[..spaceIndex] : trimmed).Trim(); if (string.IsNullOrWhiteSpace(token)) { return null; From e3c6d46ab065edeffaa0a3ea16ecc207c6554ef7 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 26 Jul 2026 09:57:09 +0000 Subject: [PATCH 3/5] Addressed PR comments --- QuickShell.Core/Services/WorkspaceHealthCheck.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/QuickShell.Core/Services/WorkspaceHealthCheck.cs b/QuickShell.Core/Services/WorkspaceHealthCheck.cs index 3004117f..efe08ac2 100644 --- a/QuickShell.Core/Services/WorkspaceHealthCheck.cs +++ b/QuickShell.Core/Services/WorkspaceHealthCheck.cs @@ -564,7 +564,8 @@ private static IEnumerable DetectPorts(TerminalShortcut shortcut) // Bolt: Performance optimization - use IndexOfAny to avoid string array allocation from Split var spaceIndex = trimmed.AsSpan().IndexOfAny(' ', '\t'); - var token = (spaceIndex >= 0 ? trimmed[..spaceIndex] : trimmed).Trim(); + var token = spaceIndex >= 0 ? trimmed[..spaceIndex] : trimmed; + if (string.IsNullOrWhiteSpace(token)) { return null; From edbd00ea11ceb04fce3ebd67fc9b9bdca823a4d8 Mon Sep 17 00:00:00 2001 From: Anthony Thompson Date: Sun, 26 Jul 2026 05:41:07 -0700 Subject: [PATCH 4/5] Potential fix for pull request finding 'CodeQL / Useless assignment to local variable' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Anthony Thompson --- QuickShell.Core/Services/LaunchCommandSanity.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/QuickShell.Core/Services/LaunchCommandSanity.cs b/QuickShell.Core/Services/LaunchCommandSanity.cs index 9fdc6ac2..142f0faa 100644 --- a/QuickShell.Core/Services/LaunchCommandSanity.cs +++ b/QuickShell.Core/Services/LaunchCommandSanity.cs @@ -68,11 +68,9 @@ public static bool IsUsableDotNetProjectFileName(string? fileName) private static bool LooksLikeTempProjectReference(string command) { // e.g. dotnet watch --project tmp_serilog_probe.csproj - // Bolt: Performance optimization - use command.AsSpan().Split(' ') to avoid string array allocations - var commandSpan = command.AsSpan(); - foreach (var range in commandSpan.Split(' ')) + foreach (var token in command.Split(' ', StringSplitOptions.RemoveEmptyEntries)) { - var tokenSpan = commandSpan[range].Trim(); + var tokenSpan = token.AsSpan().Trim(); if (tokenSpan.IsEmpty) { continue; From 60a4527a93011075455a75dd0bc57b89eb51d991 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Sun, 26 Jul 2026 13:38:14 +0000 Subject: [PATCH 5/5] fix: apply CodeRabbit auto-fixes Fixed 1 file(s) based on 1 unresolved review comment. Co-authored-by: CodeRabbit --- .../Services/LaunchCommandSanity.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/QuickShell.Core/Services/LaunchCommandSanity.cs b/QuickShell.Core/Services/LaunchCommandSanity.cs index 142f0faa..56126934 100644 --- a/QuickShell.Core/Services/LaunchCommandSanity.cs +++ b/QuickShell.Core/Services/LaunchCommandSanity.cs @@ -68,9 +68,30 @@ public static bool IsUsableDotNetProjectFileName(string? fileName) private static bool LooksLikeTempProjectReference(string command) { // e.g. dotnet watch --project tmp_serilog_probe.csproj - foreach (var token in command.Split(' ', StringSplitOptions.RemoveEmptyEntries)) + var span = command.AsSpan(); + var index = 0; + + while (index < span.Length) { - var tokenSpan = token.AsSpan().Trim(); + // Skip whitespace + while (index < span.Length && span[index] == ' ') + { + index++; + } + + if (index >= span.Length) + { + break; + } + + // Find end of token + var tokenStart = index; + while (index < span.Length && span[index] != ' ') + { + index++; + } + + var tokenSpan = span.Slice(tokenStart, index - tokenStart).Trim(); if (tokenSpan.IsEmpty) { continue;