[Repo Assist] refactor — eliminate ToLowerInvariant allocations in ChannelHealth; use TryGetValue in UpdateTrackedSession#118
Merged
shanselman merged 1 commit intomasterfrom Apr 1, 2026
Conversation
…e TryGetValue in UpdateTrackedSession ChannelHealth.IsHealthyStatus and IsIntermediateStatus each called ToLowerInvariant() on every invocation, allocating a new string for every tray menu refresh cycle. Replace with static HashSet<string> fields using StringComparer.OrdinalIgnoreCase — O(1) lookup, zero allocation per call. UpdateTrackedSession used ContainsKey + two separate indexer accesses (3–4 dict lookups). Replace with TryGetValue + local variable (2 dict lookups) — idiomatic C# that also avoids repeated hash computation. 503 + 93 tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 30, 2026
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
Two small, targeted refactors in
Models.csandOpenClawGatewayClient.cs:1.
ChannelHealth.IsHealthyStatus/IsIntermediateStatus— no moreToLowerInvariantallocationBefore:
ToLowerInvariant()allocates a newstringon every call. Both methods are invoked on every tray menu render cycle (once per channel viaMenuDisplayHelper.GetChannelStatusIcon).After:
HashSet.ContainswithOrdinalIgnoreCasecomparer does case-insensitive lookup without materialising a new stringConsistent with the existing approach in the codebase (see PR #101 eliminating
ToLowerInvariantinClassifyByKeywords, PR #105 usingFrozenDictionaryinNotificationCategorizer).2.
UpdateTrackedSession—TryGetValueinstead ofContainsKey+ double-indexerBefore:
Three to four dictionary lookups for every call.
After:
Test Status
dotnet test tests/OpenClaw.Shared.Tests/→ 503 passed, 18 skippeddotnet test tests/OpenClaw.Tray.Tests/→ 93 passedAll existing
ChannelHealth.IsHealthyStatus/IsIntermediateStatustests inModelsTests.cspass, confirming identical behaviour.