[http-client-csharp] Add Tier 1 in-memory response cache to playground-server#10718
Draft
Copilot wants to merge 3 commits into
Draft
[http-client-csharp] Add Tier 1 in-memory response cache to playground-server#10718Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
…d-server Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/693fd6ec-31da-4c6f-a4be-4324b946a6f4 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Enhance performance of C# emitter in TypeSpec playground
[http-client-csharp] Add Tier 1 in-memory response cache to playground-server
May 18, 2026
| builder.Services.AddCors(); | ||
| builder.Services.AddMemoryCache(options => | ||
| { | ||
| // Tier 1 cache cap (Item 3 of playground perf plan): 256 MB of response bodies. |
Contributor
There was a problem hiding this comment.
@copilot remove any comments pertaining to the issue. In general, we should only add comments when the code itself is not self explanatory.
Contributor
Author
There was a problem hiding this comment.
Removed the Item 3 / Tier 1 / perf-plan references and trimmed other inline comments where the code was self-explanatory in 48ddd6c.
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/656e84a4-17f1-4c10-87de-4f80c2df8412 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
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.
The playground's C#
/generateendpoint spawns a freshdotnetsubprocess on every request, with no caching anywhere in the pipeline. Identical replays (undo/redo, share-link reloads, demo specs hit by many users) pay the full cost. This implements Item 3, Tier 1 of the perf plan: a container-local in-memory response cache.Changes
playground-server/GenerationCache.cs(new) —IGenerationCache+MemoryGenerationCachebacked byIMemoryCache.ComputeKey(generatorName, codeModel, configuration, generatorVersion)returns a SHA-256 hex over a length-prefixed concatenation (avoids cross-boundary collisions like"Foo"+"Bar"vs"FooBar"+""). EntrySize= body byte length; backing cacheSizeLimit = 256 MB; 1-hour sliding expiration.playground-server/Program.cs— registersAddMemoryCache+IGenerationCachesingleton. Reads the generator DLL'sFileVersionInfo.FileVersiononce at startup and folds it into the key, so a deploy of a new binary implicitly invalidates every entry./generateshort-circuits on hit (returns cached bytes, skips the subprocess) and serializes-once-then-caches on miss. Responses carryX-Cache: HIT|MISS.playground-server.Tests/(new NUnit project, 15 tests) — key determinism & format; sensitivity to each of the four components (including version → invalidation); length-prefix unambiguity; null-argument guards; get/miss/set/overwrite round-trip;SizeLimitcompaction; sliding-expiration eviction.Cache flow
Out of scope
Tier 2 file-based cache and Items 1/2/4/5 of the issue. Generator internals are untouched; production
tspcodegen is unaffected.