-
Notifications
You must be signed in to change notification settings - Fork 3
Avoid extra allocation/clone in SubgraphExecutionRequest #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @ardatan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request primarily focuses on optimizing the performance of GraphQL request processing, especially for calls made to subgraphs. It achieves this by refactoring internal data structures to minimize memory allocations and data cloning, ensuring that query strings, operation names, and variables are passed by reference where possible. Additionally, it includes general improvements to the query projection logic to further reduce allocations and refines the gateway's handling of incoming requests.
Highlights
- Reduced Allocations for Subgraph Requests: I've introduced a new
SubgraphExecutionRequeststruct that utilizes borrowed data (&str,&Value) for query strings, operation names, and variables. This change significantly reduces memory allocations and data cloning when preparing and executing requests against subgraphs, leading to improved performance. - Improved Subgraph Executor Interface: The
SubgraphExecutortrait and its various implementations (e.g., for HTTP andasync-graphqlexecutors) have been updated to accept the new, more efficientSubgraphExecutionRequesttype, ensuring that all subgraph communication benefits from the reduced allocation strategy. - Gateway Request Type Refactoring: The
ExecutionRequeststruct, which represents incoming GraphQL requests at the gateway level, has been redefined and isolated withinbin/gateway/src/pipeline/graphql_request_params.rs. This clarifies the separation between the gateway's external request handling and the internal subgraph execution logic. - Optimized Query Projection: I've refactored several functions within the query projection logic (
lib/query-plan-executor/src/projection.rs) to operate on immutable references and eliminate unnecessary string allocations. These general improvements contribute to overall performance gains beyond just subgraph requests.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
Federation Audit Results188 tests ±0 177 ✅ ±0 3s ⏱️ ±0s For more details on these failures, see this check. Results for commit 5c02b42. ± Comparison against base commit 7b6ac07. ♻️ This comment has been updated with latest results. |
|
e808033 to
ca72f46
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces the SubgraphExecutionRequest to avoid extra allocation/clone in subgraph requests. The changes are well-propagated through the executor implementations. There are a few suggestions for better maintainability and readability.
ca72f46 to
5c02b42
Compare
✅
|
5308c5e to
80a25ea
Compare
| // We may want to remove it, but let's see. | ||
| let mut body = String::with_capacity(4096); | ||
| body.push_str("{\"query\":"); | ||
| write_and_escape_string(&mut body, execution_request.query); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
| let mut body = | ||
| "{\"query\":".to_string() + &serde_json::to_string(&execution_request.query).unwrap(); | ||
| // We may want to remove it, but let's see. | ||
| let mut body = String::with_capacity(4096); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4096 is generally enough? how did we end up with this value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will never be correct
dotansimha
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. @kamilkisiela please review as well.
80a25ea to
a5d0ef0
Compare
a5d0ef0 to
7d58d87
Compare
Avoid cloning variables and operation string(aka `query`) for subgraph requests
Avoid cloning variables and operation string(aka `query`) for subgraph requests
Avoid cloning variables and operation string(aka `query`) for subgraph requests
Avoid cloning variables and operation string(aka
query) for subgraph requests