Skip to content

perf: cache JsonSerializerOptions and compiled Regex in WindowsNodeClient - #68

Merged
shanselman merged 1 commit into
masterfrom
perf/cache-serialization-options
Mar 18, 2026
Merged

shanselman merged 1 commit into
masterfrom
perf/cache-serialization-options

Conversation

@shanselman

Copy link
Copy Markdown
Collaborator

Caches hot-path allocations in WindowsNodeClient message handlers.

Changes

  • \s_ignoreNullOptions: static \JsonSerializerOptions\ with \WhenWritingNull\ (was
    ew\ per invoke result/response)
  • \s_indentedOptions: static \JsonSerializerOptions\ with \WriteIndented\ (was
    ew\ per debug log)
  • \s_commandValidator: static compiled \Regex\ for command format validation (was inline \Regex.IsMatch\ per message)

Impact

  • Eliminates 2-4 \JsonSerializerOptions\ allocations per node command cycle
  • Eliminates regex compilation per message (2 call sites)
  • Follows existing caching patterns in ExecApprovalPolicy and NotificationCategorizer

Inspired by Repo Assist #65 (rebased to post-WebSocketClientBase refactor code).

All 503 shared tests pass, 0 warnings.

Co-authored-by: Copilot [email protected]

…ient

- Add static readonly s_ignoreNullOptions (WhenWritingNull) — was allocated per-message
- Add static readonly s_indentedOptions (WriteIndented) — was allocated per debug log
- Add static compiled s_commandValidator Regex — was recompiled per-message
- Eliminates per-message allocations in hot-path node.invoke handlers

Inspired by Repo Assist #65 (rebased to post-refactor code).

Co-authored-by: Copilot <[email protected]>
@shanselman
shanselman merged commit 536d436 into master Mar 18, 2026
14 checks passed
@vincentkoc
vincentkoc deleted the perf/cache-serialization-options branch August 2, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant