Skip to content

Refactor: Introduce compiled projection artifacts#2119

Draft
kamilkisiela wants to merge 2 commits intomainfrom
kamil-random-perf
Draft

Refactor: Introduce compiled projection artifacts#2119
kamilkisiela wants to merge 2 commits intomainfrom
kamil-random-perf

Conversation

@kamilkisiela
Copy link
Copy Markdown
Contributor

This commit introduces compiled projection artifacts to optimize response shaping and projection.

The changes include:

  • Defining new types for compiled projection plans and artifacts.
  • Caching compiled projection artifacts based on the GraphQL document.
  • Modifying createQueryPlanExecutionContext to use the new compiled projection artifacts.
  • Updating projectSelectionSet to utilize the compiled projection structure.
  • Introducing helper functions for managing compiled projections and related caches.

This commit introduces compiled projection artifacts to optimize
response shaping and projection.

The changes include:
- Defining new types for compiled projection plans and artifacts.
- Caching compiled projection artifacts based on the GraphQL document.
- Modifying `createQueryPlanExecutionContext` to use the new compiled
  projection artifacts.
- Updating `projectSelectionSet` to utilize the compiled projection
  structure.
- Introducing helper functions for managing compiled projections and
  related caches.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 introduces a significant architectural enhancement to the GraphQL execution pipeline by implementing compiled projection artifacts. This refactoring aims to boost performance by transforming GraphQL operation selection sets and fragments into an optimized, pre-processed format. By caching these compiled artifacts and associated runtime metadata, the system can execute response shaping and data projection more efficiently, reducing overhead and improving overall query execution speed. The changes also include optimized merging strategies and a more robust hashing mechanism for entity identification.

Highlights

  • Introduced Compiled Projection Artifacts: New data structures were added to represent pre-compiled GraphQL selection sets and fragments, optimizing response shaping.
  • Implemented Caching Mechanisms: Caching for compiled projection artifacts and runtime metadata (like field meta and inaccessible types) was added to improve performance by avoiding redundant computations.
  • Refactored Projection Logic: The projectSelectionSet and projectRequires functions were updated to utilize the new compiled artifacts and associated helper functions for more efficient processing.
  • Optimized Data Merging and Hashing: Custom mergeEntityPayload and mergeProjectedFieldValue functions were introduced for faster object merging, and a new hashValueOrderIndependent32Ultra replaced stableStringify for improved identity mapping.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 a significant refactoring to optimize response shaping and projection by using compiled projection artifacts. The changes involve pre-compiling parts of the GraphQL query document into more efficient data structures and leveraging multiple layers of caching. The implementation also replaces generic utility functions like mergeDeep and stableStringify with highly optimized, specialized versions. Overall, this is a well-structured performance enhancement. I have one suggestion to improve code clarity and maintainability regarding the stableStringify function.

Comment on lines +1304 to 1306
function stableStringify(value: unknown) {
return hashValueOrderIndependent32Ultra(value);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This function now returns a number (a hash), not a string. The name stableStringify is therefore misleading. A rename to something like stableHashValue would be ideal, but that would affect code outside of this diff. As a minimum, please add an explicit return type for clarity. A TSDoc comment explaining that the function returns a hash would also be beneficial for future maintainability.

Suggested change
function stableStringify(value: unknown) {
return hashValueOrderIndependent32Ultra(value);
}
function stableStringify(value: unknown): number {
return hashValueOrderIndependent32Ultra(value);
}

@theguild-bot
Copy link
Copy Markdown
Collaborator

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-hive/router-runtime 1.2.2-alpha-b774088bb01fe98728963ba332f8a4b4406ce776 npm ↗︎ unpkg ↗︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants