perf(mcp): cache CalendarTools JsonSerializerOptions instead of per-call allocation (CA1869) #682

Closed
opened 2026-07-17 20:07:27 +00:00 by spikerj · 1 comment
Owner

CalendarTools (MCP server) serialized its tool responses with a fresh JsonSerializerOptions ({ WriteIndented = true, PropertyNamingPolicy = CamelCase }) at all 4 serialize sites. System.Text.Json caches type metadata per options-instance, so a new instance each call rebuilds that reflection cache (CA1869).

Hoist the identical config to one static readonly IndentedCamelCase instance. No behavior change; immutable after first use, safe for concurrent reads. Build clean. Continuation of #364 (BookController) / #379 (KeycloakAdminService). SonarQube rule external_roslyn:CA1869.

CalendarTools (MCP server) serialized its tool responses with a fresh JsonSerializerOptions ({ WriteIndented = true, PropertyNamingPolicy = CamelCase }) at all 4 serialize sites. System.Text.Json caches type metadata per options-instance, so a new instance each call rebuilds that reflection cache (CA1869). Hoist the identical config to one static readonly IndentedCamelCase instance. No behavior change; immutable after first use, safe for concurrent reads. Build clean. Continuation of #364 (BookController) / #379 (KeycloakAdminService). SonarQube rule external_roslyn:CA1869.
Author
Owner

Resolved in spikersoft-backend PR #380 (merged to master). Hoisted CalendarTools' 4 per-call JsonSerializerOptions to one static readonly instance; no behavior change. Closing.

Resolved in spikersoft-backend PR #380 (merged to master). Hoisted CalendarTools' 4 per-call JsonSerializerOptions to one static readonly instance; no behavior change. Closing.
Sign in to join this conversation.