feature request: AppSync: cache the executable schema per API, so that a request's cost no longer grows with the schema's size #90
Closed
mattiarossi
started this conversation in
Feature Requests (AWS)
Replies: 1 comment 2 replies
|
Hello @mattiarossi and thanks again for the report! We've just merged this feature now, and locally we could validate the speed up. Let me know if the improvement is good enough for you! Really thankful for all of these reports 🙏 |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Is there an existing issue for this?
Feature description
Build the executable GraphQL schema of an AppSync API once, when
start-schema-creationcompletes, and keep it in memory keyed by the API id and the schema's version, so that each request pays only its own parse, validation and execution. Today the per-request cost of a GraphQL API is proportional to the size of its schema, on every request, whether or not a resolver is involved, so an API with a large schema answers{ __typename }in hundreds of milliseconds to seconds where a one-type API answers in ten.Current behaviour, measured
A throwaway API-key API whose schema carries N generated types (ten
Stringfields each, every type reachable fromQuery), ten sequential{ __typename }requests with the API key after one warm-up, wall time from a workstation on the same LAN, no resolver attached to anything (repro-schema-cost.sh, run 2026-11-17 onlocalstack/localstack:dev2026.11.0.dev1060, Pro):{ __typename }medianThe cost is linear in the schema up to a thousand types and worse beyond, and it is paid on every request: the eleventh request costs what the first did. The gateway itself answers
/_localstack/healthin 8 ms on the same instance, and a malformed query ({ __typenameunterminated) is refused in 17 ms on the large schema, so the request's own parse is cheap and comes first; what remains between the parse and the (absent) resolver is the schema, built or validated per request in time proportional to its size.The same on a real application: an Amplify Gen 2 backend whose schema is exported from PostGraphile (17,261 lines, 459 KB, 261
@aws_iamdirectives) pays a 600 ms floor per request on this host for{ __typename }, with or without a Cognito token, and the same floor with its Lambda resolver invoked (the resolver's own share is about 30 ms). Measured unchanged on 2026.10.7, 2026.11.0.dev958 and dev1060. The floor scales with the host's single-thread speed, as interpreter work does: 600 ms on an AMD EPYC 7402P, 240 ms on an Apple M5 Max, same schema, same image line. Cold starts and container work are not involved: the figures are the same with the resolver's container warm.Why it matters
Amplify Gen 2 applications have schemas of this size by construction (PostGraphile's export here; the data transformer's for a
defineDatamodel app), so every page of such an application pays this on every query: a page of twenty queries is twelve seconds on the server above, five on the laptop, against well under a second on AWS, where the same request costs tens of milliseconds whatever the schema. In our evaluation of LocalStack Pro for the daily development loop this is the one item that keeps the local stack from being usable from the client; every other gap found so far (discussion #88, #89) has a workaround or a fix in thedevimage.Suggested implementation
start-schema-creationlands (the SDL is already parsed there for the status), store it with the API, and hand the stored object to the request path; invalidate on the next schema creation and on API deletion.{ __typename }row is flat across the table above, about 10 ms at every size, and the application's floor drops to the gateway's.How are you starting LocalStack?
Docker Compose under Portainer (LocalStack Pro,
localstack/localstack:dev2026.11.0.dev1060,PERSISTENCE=1,SNAPSHOT_SAVE_STRATEGY=ON_SHUTDOWN,SNAPSHOT_LOAD_STRATEGY=ON_STARTUP), the AWS CLI andcurlfrom a workstation on the same LAN.repro-schema-cost.shcreates the five APIs above and deletes them;SIZESandENDPOINTselect the sizes and the instance.Environment
localstack/localstack:dev, Pro token); the application figures also on 2026.10.7 and dev958Evidence
repro-schema-cost.sh
All reactions