Skip to content

[Repo Assist] perf: eliminate LINQ Skip allocations in ExecShellWrapperParser#193

Merged
shanselman merged 1 commit intomasterfrom
repo-assist/perf-execshell-tokenize-skip-2026-04-21-40aba020e3b55e57
Apr 23, 2026
Merged

[Repo Assist] perf: eliminate LINQ Skip allocations in ExecShellWrapperParser#193
shanselman merged 1 commit intomasterfrom
repo-assist/perf-execshell-tokenize-skip-2026-04-21-40aba020e3b55e57

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist.

Summary

Eliminates LINQ Skip iterator allocations in the shell-payload reconstruction path of ExecShellWrapperParser.

What changed

Three calls of the form:

string.Join(" ", tokens.Skip(i + 1)).Trim()

are replaced with the indexed BCL overload:

string.Join(" ", tokens, i + 1, tokens.Length - i - 1).Trim()

The three sites are:

  • cmd /c and cmd /k payload reconstruction
  • bash -c / sh -c payload reconstruction
  • powershell -Command / pwsh -Command payload reconstruction

Supporting changes:

  • Tokenize() return type changed from List<string> to string[] (returns tokens.ToArray()) so the indexed string.Join overload is available.
  • ParsePowerShellPayload parameter type updated from IReadOnlyList<string> to string[] to match.
  • using System.Linq; removed (now unused).

Why

Each tokens.Skip(i + 1) call allocates a LINQ WhereEnumerableIterator/SkipEnumerable wrapper. 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 warnings
  • dotnet test OpenClaw.Shared.Tests — passed (exit 0)
  • dotnet test OpenClaw.Tray.Tests — passed (exit 0)

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a

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>
@shanselman shanselman marked this pull request as ready for review April 23, 2026 17:25
@shanselman shanselman merged commit 76fb1dc into master Apr 23, 2026
@shanselman shanselman deleted the repo-assist/perf-execshell-tokenize-skip-2026-04-21-40aba020e3b55e57 branch April 23, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant