[Repo Assist] perf: cache HTML sanitize regex; replace ToLowerInvariant with FrozenDictionary; fix GetRawText double-call#105
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Conversation
…Dictionary in ShouldShowNotification; fix GetRawText double-call - CanvasWindow.SanitizeHtml: two anonymous Regex.Replace calls now use static readonly compiled fields (s_sanitizeBlock, s_sanitizeSelfClose). Previously each call to SanitizeHtml recompiled both patterns from scratch (Regex JIT + allocation on every canvas load). - App.ShouldShowNotification: replaced 'Type?.ToLowerInvariant()' switch with a static FrozenDictionary<string, Func<SettingsManager, bool>> using OrdinalIgnoreCase. Runs for every incoming notification; old code allocated a lowercase string copy every call; new code does an O(1) hash-table lookup with zero allocation. - OpenClawGatewayClient.HandleChatEvent: GetRawText() was called twice in the same debug expression, materialising the JSON string twice. Now called once and stored in a local. All 503 shared tests pass, 18 skipped (infra). All 93 Tray tests pass. WinUI build fails on Linux (XAML compiler is Windows-only PE) — same infrastructure limitation as all other WinUI PRs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
26 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 draft PR from Repo Assist.
Summary
Three targeted performance fixes across two hot-path methods and one debug statement.
1.
CanvasWindow.SanitizeHtml— cache HTML sanitization regex patternsBefore: Two
Regex.Replace()calls with inline pattern strings — the .NETRegexstatic method recompiles each pattern from scratch on every invocation.After: Two
static readonlycompiledRegexfields (s_sanitizeBlock,s_sanitizeSelfClose). Pattern compilation happens once at startup; subsequent calls do a hash-table lookup and apply the pre-JIT'd automaton directly. Zero per-call allocation.SanitizeHtml runs every time canvas content is loaded or navigated, so this avoids repeated Regex JIT work.
2.
App.ShouldShowNotification— replaceToLowerInvariant()switch withFrozenDictionaryBefore:
notification.Type?.ToLowerInvariant()allocated a lowercase string copy on every incoming notification before the switch evaluation.After:
static readonly FrozenDictionary(string, Func<SettingsManager, bool)>withOrdinalIgnoreCasecomparer — O(1) case-insensitive hash lookup, no per-call allocation. Matches the pattern already applied toClassifyToolin PR #101.ShouldShowNotification runs for every notification received from the gateway.
3.
OpenClawGatewayClient.HandleChatEvent— eliminate duplicateGetRawText()callBefore:
root.GetRawText().Substring(0, Math.Min(200, root.GetRawText().Length))calledGetRawText()twice, materialising the full JSON string twice.After: Result stored in a local variable; second materialisation eliminated.
Test Status
✅ All 503 shared tests pass, 18 skipped (infrastructure-only).
⚠️
dotnet test tests/OpenClaw.Shared.Tests/✅ All 93 Tray tests pass.
dotnet test tests/OpenClaw.Tray.Tests/dotnet build src/OpenClaw.Tray.WinUIis not buildable on Linux (XAML compiler is a Windows-only PE binary) — same infrastructure limitation as all other WinUI PRs. Logic verified by inspection; changes are purely additive fields and method body updates.