perf(graph): cache merged SDL and SchemaUpdate per ref #841
Reference in New Issue
Block a user
Delete Branch "precompute-schema-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Both
SupergraphandLatestSchemaresolvers were recomputing their result on every request.Why this matters
Supergraph:sdlmerge.MergeSDLs()runs AST validation + normalization + custom merge walkers over all subgraph SDLs.LatestSchema:CosmoGenerator.Generate()shells out towgc router compose(Node via npx) — spends 100-300m CPU per call.The output is fully determined by the set of subgraph SDLs and their
lastUpdatetimestamp, so it can be cached and reused across requests until aSubGraphUpdatedevent bumpslastUpdatefor the(orgId, ref)key.What this PR does
Adds two precomputation caches to
cache.Cache, both versioned by the existinglastUpdatemap so a single timestamp comparison invalidates stale entries implicitly:mergedSDLs— cachedMergeSDLsoutput forSupergraphschemaUpdates— cachedSchemaUpdate(subgraphs + cosmo config) forLatestSchemaThe
UpdateSubGraphdebounce already computes the cosmo config to publish through PubSub; it now also stores theSchemaUpdateso the nextLatestSchemaquery is warm.OrganizationRemovedevicts both caches alongsidelastUpdate.Expected effect
Eliminates the per-request CPU bursts that were tripping the HPA into
TooManyReplicasterritory (the symptom that drove #840). After the first request per(orgId, ref)post-update, subsequent queries return in microseconds from the in-memory cache.