[Repo Assist] perf: eliminate LINQ Skip allocations in ExecShellWrapperParser#193
Merged
shanselman merged 1 commit intomasterfrom Apr 23, 2026
Conversation
Replace string.Join(", ", tokens.Skip(i + 1)) with the indexed
string.Join(string, string[], int, int) overload in the three shell-
payload reconstruction sites (cmd /c, bash -c, powershell -Command).
Changes:
- Tokenize() now returns string[] instead of List<string>; callers
already received it as an opaque list so the type narrowing is safe.
- ParsePowerShellPayload signature updated to string[] to match.
- Three string.Join(" ", tokens.Skip(i + 1)) calls replaced with
string.Join(" ", tokens, i + 1, tokens.Length - i - 1) — uses the
well-known BCL overload that slices directly into the array with no
iterator allocation.
- Removes the now-unused 'using System.Linq;' import.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated PR from Repo Assist.
Summary
Eliminates LINQ
Skipiterator allocations in the shell-payload reconstruction path ofExecShellWrapperParser.What changed
Three calls of the form:
are replaced with the indexed BCL overload:
The three sites are:
cmd /candcmd /kpayload reconstructionbash -c/sh -cpayload reconstructionpowershell -Command/pwsh -Commandpayload reconstructionSupporting changes:
Tokenize()return type changed fromList<string>tostring[](returnstokens.ToArray()) so the indexedstring.Joinoverload is available.ParsePowerShellPayloadparameter type updated fromIReadOnlyList<string>tostring[]to match.using System.Linq;removed (now unused).Why
Each
tokens.Skip(i + 1)call allocates a LINQWhereEnumerableIterator/SkipEnumerablewrapper.string.Join(string, string[], int, int)takes the array and index/count directly — no iterator object is created.This fires on every shell-wrapped command that arrives over the node connection (
cmd /c ...,bash -c ...,powershell -Command ...).Test Status
dotnet build— succeeded, 0 errors, 0 warningsdotnet test OpenClaw.Shared.Tests— passed (exit 0)dotnet test OpenClaw.Tray.Tests— passed (exit 0)