Skip to content

[Repo Assist] perf(shared): eliminate LINQ sort and repeated Contains calls in ChannelsAggregator#532

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
repo-assist/perf-channels-aggregator-2026-05-24-375bd1b84be0213e
Draft

[Repo Assist] perf(shared): eliminate LINQ sort and repeated Contains calls in ChannelsAggregator#532
github-actions[bot] wants to merge 1 commit into
masterfrom
repo-assist/perf-channels-aggregator-2026-05-24-375bd1b84be0213e

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist.

What

Two small allocation reductions in ChannelsAggregator.Aggregate(), which is called on every channel-status update pushed from the gateway to the UI.

Changes

1. Hoist repeated QrLinkChannels.Contains(id) to a local bool

Previously the loop called QrLinkChannels.Contains(id) twice per channel (once for CanShowQr/CanRelink, once for CanStop). Hoisting to var isQrChannel = QrLinkChannels.Contains(id) avoids the second hash lookup.

2. Replace LINQ sort with List<T>.Sort()

The OrderByDescending(r => r.IsConfigured).ThenBy(r => r.SortOrder).ToList() chain creates:

  • An IOrderedEnumerable<T> wrapper, and
  • A second List<ChannelRecord> materialisation

Replacing with records.Sort(static (a, b) => ...) sorts in-place with a static Comparison<T> delegate — no extra allocations. The sort order is identical (configured channels first, then by SortOrder).

Behaviour

No behaviour change. The existing ChannelsPipelineTests and ChannelsStatusTests pass unchanged.

Test Status

dotnet build on OpenClaw.Shared.Tests succeeds. Test run shows 8 pre-existing failures (identical to master baseline) — no new failures introduced.


Generated by 🌈 Repo Assist. 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

…nelsAggregator

ChannelsAggregator.Aggregate() is called on every gateway channel status
update pushed to the UI. Two small allocation sources were unnecessary:

1. QrLinkChannels.Contains(id) was called twice per channel (once for
   CanShowQr/CanRelink and once for CanStop). Hoist to a local bool.

2. The final sort used LINQ OrderByDescending/ThenBy/ToList, which creates
   an IOrderedEnumerable wrapper and then materialises a second List<T>.
   Replace with List<T>.Sort() (in-place, no extra allocation) using a
   static Comparison<T> delegate.

No behaviour change — the sort order (configured-first, then by SortOrder)
is identical.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented May 24, 2026

Codex review: needs maintainer review before merge.

Latest ClawSweeper review: 2026-05-24 13:05 UTC / May 24, 2026, 9:05 AM ET.

Workflow note: Future ClawSweeper reviews update this same comment in place.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Summary
The PR caches QR-channel membership in ChannelsAggregator.Aggregate() and replaces the final LINQ ordering chain with an in-place List<T>.Sort() comparator.

Reproducibility: not applicable. this is a pull-request cleanup review rather than a bug report. The relevant source check is that current main still uses LINQ ordering and repeated QrLinkChannels.Contains(id) calls in ChannelsAggregator.Aggregate().

PR rating
Overall: 🐚 platinum hermit
Proof: 🌊 off-meta tidepool
Patch quality: 🐚 platinum hermit
Summary: The patch is small and behavior-preserving by source inspection, with normal merge confidence pending maintainer-side validation.

Rank-up moves:

  • Run the repository-required build and shared/tray test commands in a writable validation environment before merge.
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Real behavior proof
Not applicable: This is an automated bot PR, so the external contributor real-behavior-proof gate is not applied; merge confidence should come from source review and repository validation.

Risk before merge

  • Writable validation is still needed before merge; this read-only review did not run the repository build or tests because those commands can create artifacts.

Maintainer options:

  1. Decide the mitigation before merge
    Land the small allocation cleanup if maintainers are comfortable after the repository’s required build and test validation.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge
No automated repair is needed; the remaining action is maintainer validation and merge judgment for a small cleanup PR.

Security
Cleared: The diff only changes in-memory channel aggregation logic and does not touch dependencies, CI, secrets, credentials, or code-loading paths.

Review details

Best possible solution:

Land the small allocation cleanup if maintainers are comfortable after the repository’s required build and test validation.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this is a pull-request cleanup review rather than a bug report. The relevant source check is that current main still uses LINQ ordering and repeated QrLinkChannels.Contains(id) calls in ChannelsAggregator.Aggregate().

Is this the best way to solve the issue?

Yes: caching the QR lookup and sorting the already-built list in place is a narrow maintainable performance improvement because SortOrder is a unique loop index, preserving the existing configured-first ordering.

Label justifications:

  • P3: This is a narrow performance cleanup in shared channel aggregation with no confirmed user-visible behavior change.
  • rating: 🐚 platinum hermit: Current PR rating is 🐚 platinum hermit because proof is 🌊 off-meta tidepool, patch quality is 🐚 platinum hermit, and The patch is small and behavior-preserving by source inspection, with normal merge confidence pending maintainer-side validation.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is an automated bot PR, so the external contributor real-behavior-proof gate is not applied; merge confidence should come from source review and repository validation.

What I checked:

  • Current main still has the cleanup target: ChannelsAggregator.Aggregate() still calls QrLinkChannels.Contains(id) in both QR capability and CanStop checks and still returns a LINQ OrderByDescending(...).ThenBy(...).ToList() chain on current main. (src/OpenClaw.Shared/ChannelRecord.cs:179, ef6ac8acbab2)
  • Sort equivalence check: The list is built from BuildOrderedIds() and each record receives SortOrder = i, so comparing configured state and then SortOrder is equivalent to the current LINQ ordering for unique records. (src/OpenClaw.Shared/ChannelRecord.cs:149, ef6ac8acbab2)
  • Existing tests cover visible ordering expectations: The shared pipeline test expects configured channels first, followed by unconfigured gateway and built-in channels in gateway/fallback order. (tests/OpenClaw.Shared.Tests/ChannelsPipelineTests.cs:42, ef6ac8acbab2)
  • Feature history provenance: git blame ties the central aggregator ordering and capability logic to the channel-page implementation/refinement commits, with later QR CanStop logic added in the richer channel controls work. (src/OpenClaw.Shared/ChannelRecord.cs:80, c417cbae147d)
  • Related discussion context: The provided PR context shows this came from the Repo Assist monthly activity item and the previous ClawSweeper review had no findings, with the same head SHA b164e755ac5747cad1faaabc84ea7c991ed9a471. (b164e755ac57)

Likely related people:

  • bakudies: Git blame and string history tie the channel aggregator ordering and QR capability logic to the channel page work in May 2026. (role: feature-history owner; confidence: high; commits: c417cbae147d, bb10df6acfcf; files: src/OpenClaw.Shared/ChannelRecord.cs, tests/OpenClaw.Shared.Tests/ChannelsStatusTests.cs)

Codex review notes: model gpt-5.5, reasoning high; reviewed against ef6ac8acbab2.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. labels May 24, 2026
@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented May 24, 2026

ClawSweeper PR egg

✨ Hatched: 🌱 uncommon Frosted Proofling

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🌱 uncommon.
Trait: guards the happy path.
Image traits: location status garden; accessory miniature diff map; palette rose quartz and slate; mood watchful; pose guarding a tiny green check; shell soft speckled shell; lighting gentle morning glow; background gentle dashboard dots.
Share on X: post this hatch
Copy: My PR egg hatched a 🌱 uncommon Frosted Proofling in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. performance rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. repo-assist status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants