Skip to content
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

introduces mapSchemaConfig utility function #4297

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yaacovCR
Copy link
Contributor

@yaacovCR yaacovCR commented Nov 19, 2024

motivation:

  1. rebuilds lexicographicSortSchema() on this generic utility, better demonstrating only the sorting
  2. rebuilds extendSchemaImpl() on this utility
  3. can be used as base to more easily enhance extendSchema()/buildASTSchema()/buildSchema() to take resolvers, etc
  4. can be used to expose a generic safe mapSchemaConfig() utility
  5. improved performance -- not the initial motivation, but turns out these changes bring an 80% speed improvement to buildSchema().

@yaacovCR yaacovCR requested a review from a team as a code owner November 19, 2024 11:23
Copy link

netlify bot commented Nov 19, 2024

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit d4b0152
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/6745b418d6c61200080cc024
😎 Deploy Preview https://deploy-preview-4297--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

Hi @yaacovCR, I'm @github-actions bot happy to help you with this PR 👋

Supported commands

Please post this commands in separate comments and only one per comment:

  • @github-actions run-benchmark - Run benchmark comparing base and merge commits for this PR
  • @github-actions publish-pr-on-npm - Build package from this PR and publish it on NPM

@yaacovCR yaacovCR changed the title introduces mapSchema function introduces mapSchemaConfig function Nov 19, 2024
@yaacovCR
Copy link
Contributor Author

note: diff is easier to scan when hiding whitespace

@yaacovCR yaacovCR changed the title introduces mapSchemaConfig function introduces mapSchemaConfig utility function Nov 19, 2024
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Nov 21, 2024

This re-implementation brings a 24% performance boost to buildSchema() and a small drop in memory use.

image

I'm not sure yet what exactly brings the performance boost, I was just hoping for parity.

@yaacovCR
Copy link
Contributor Author

Just poking around a bit with deopt-explorer, which, as usual, is beyond me, but the summary for main is:

image

and the summary for map is:

image

For clarity, within the map version, we rename getWrappedType() to typeFromAST() and getNamedType() to namedTypeFromAST() because it allows us to use getNamedType() in the SchemaContext closure without a clash -- and these functions essentially are a pre-GraphQLSchema-creation version of our typeFromAST() utility with the exact same algorithm.

For clarity, I also renamed buildType() to buildNamedType().

So the thing that leaps out at me is that the number of deoptimizations in buildType()/buildNamedType() and extendSchemaImpl() drop, the former significantly. I am not 100% on why. I can only guess that splitting the functions into smaller bits helped.

@yaacovCR yaacovCR added the PR: polish 💅 PR doesn't change public API or any observed behaviour label Nov 26, 2024
@yaacovCR
Copy link
Contributor Author

UPDATE:

  • I have separated out the commits introducing mapSchemaConfig() and those used to rebuild lexicographicSortSchema() and extendSchemaImpl(), the latter underlying buildSchema() and extendSchema().
  • The initial commit has full test coverage on its own.
  • I have introduced another "helper" method available to the mapper functions, getNamedTypes() which means that we don't have to manually track the added types and then concatenate them to the pre-existing types within extendSchemaImpl().

Benchmark results from current version are even better than before, an ~80% improvement on main:

image

@graphql graphql deleted a comment from github-actions bot Nov 26, 2024
@graphql graphql deleted a comment from github-actions bot Nov 26, 2024
motivation:
1. can be used to extract common logic from extendSchemaImpl and lexicographicSortSchema
2. can be used further enhance extendSchemaImpl to take resolvers
3. can be exposed to provide a generic safe mapSchemaConfig
@yaacovCR

This comment has been minimized.

Copy link

@github-actions publish-pr-on-npm

@yaacovCR The latest changes of this PR are available on NPM as
graphql@17.0.0-alpha.7.canary.pr.4297.42bcd01f7c733e255ff9eab84ec8d7500dfd208a
Note: no gurantees provided so please use your own discretion.

Also you can depend on latest version built from this PR:
npm install --save graphql@canary-pr-4297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: polish 💅 PR doesn't change public API or any observed behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant