feat: add bytecode compilation and execution for GraphQL responses#1494
feat: add bytecode compilation and execution for GraphQL responses#1494TheApeMachine wants to merge 2 commits into
Conversation
This commit introduces a new bytecode compilation and execution mechanism for GraphQL responses, enhancing performance and flexibility. It includes the implementation of various benchmarks and tests to ensure correctness and efficiency in processing GraphQL queries. New structures and functions for handling bytecode operations, including direct responses and nested object handling, have been added to improve the overall architecture of the engine.
📝 WalkthroughWalkthroughThis pull request implements a complete bytecode compilation and execution system for GraphQL federation response resolution. The changes introduce an optimized instruction-based execution model that bypasses traditional fetch-tree traversal and enables direct-response rendering via byte-range extraction from subgraph JSON. ChangesBytecode Compilation and Execution Pipeline
Sequence DiagramssequenceDiagram
participant GraphQL Plan
participant Compiler
participant FetchOps as Fetch Ops
participant ResponseOps as Response Ops
participant StringRefs as String/Path Refs
participant Program
GraphQL Plan->>Compiler: plan input
Compiler->>FetchOps: compileFetchTree
Compiler->>ResponseOps: compileNode
FetchOps->>StringRefs: registerFetch, pathRef
ResponseOps->>StringRefs: stringRef, pathRef
StringRefs->>Program: deduplicate entries
FetchOps->>Program: append fetch records
ResponseOps->>Program: append ops
Compiler->>Program: add DirectResponse if eligible
sequenceDiagram
participant Request as GraphQL Request
participant Resolver as ResolveGraphQLResponseBytecode
participant Loader as LoadGraphQLResponseDataBytecode
participant FetchExec as executeBytecodeSpan
participant DirectRender as renderDirectResponseBytecode
participant Merge as mergeRawFetchResults
participant Output as JSON Writer
Request->>Resolver: invoke with program
Resolver->>Loader: load bytecode data
Loader->>FetchExec: walk ops, resolve fetches
FetchExec->>FetchExec: recursively execute sequences/parallels
Loader->>DirectRender: attempt direct response
DirectRender->>DirectRender: selectDirectValueSources from byte ranges
DirectRender->>Output: emit JSON directly
alt Direct render succeeds
Output->>Resolver: fast path done
else Direct render unavailable
Loader->>Merge: merge raw fetch results
Merge->>Output: emit JSON from merged data
end
Resolver->>Output: finalize response
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @TheApeMachine, wow, this is a pretty big change! Could you consider adding some more background to how your change works, your motivation, how you implemented it? Being completely honest my main concern with PRs like this is that it's 5000 new lines of code that our team has to become comfortable enough with what you've written to adopt it into our codebase and offer long term support for it. It's difficult to justify this based on purely the implementation and microbenchmarks (ns scale), so sharing some background would be great. |
|
@endigma Fully understand, and I will add some more background. However, just to make it clear, this was more in response to the question about what you would change, which was presented in the recruitment form. So please don't spend your time on this if this is not something you truly want/need to pursue. On the other hand, if performance is something on your roadmap, I believe there is a viable path for gains here. I will add the background in any case for completeness tomorrow. |
|
Hi @TheApeMachine, thanks for letting me know, I think this could be a good idea, but I don't think we'll be merging something like this at this time unless you've motivated your change with a real issue. Of course good luck with our hiring process! |
@coderabbitai summary
Checklist
This commit introduces a new bytecode compilation and execution mechanism for GraphQL responses, enhancing performance and flexibility. It includes the implementation of various benchmarks and tests to ensure correctness and efficiency in processing GraphQL queries. New structures and functions for handling bytecode operations, including direct responses and nested object handling, have been added to improve the overall architecture of the engine.
Using the final
-count=3benchmark run on Apple M4 Max:Command used:
Interpretation: the best case is the static-shape nested query, where the bytecode direct renderer gets almost exactly the 1.5x target and cuts allocs by two thirds. Entity cases are more modest because they still pay ASTJSON merge/fetch-input costs, but they consistently reduce alloc count and still land around 1.12x-1.26x faster.