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

Only compute ClientSideBaseVisitor's fragmentsGraph once, at instantiation time #10019

Merged
merged 3 commits into from
Jun 24, 2024

Conversation

vhfmag
Copy link
Contributor

@vhfmag vhfmag commented Jun 21, 2024

Description

As mentioned in #10018, ClientSideBaseVisitor's fragmentsGraph is implemented as a getter, despite not depending on anything that changes after the class is first instantiated. Turning fragmentsGraph into a static property improved build time from ~130s to ~50s in a big monorepo.

This PR does that and it makes field fragmentsGraph depends on (_fragments) read-only to make sure we don't break the assumption behind pre-computing the former.

Related: #10018

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Screenshots/Sandbox (if appropriate/relevant):

Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate

How Has This Been Tested?

  • Run codegen on a mid-sized project using client-preset and measure the build time
  • Make the change to only compute fragmentsGraph once per ClientSideBaseVisitor instance
  • Run codegen again and compare the build time

Test Environment:

  • OS: macOS
  • NodeJS: 18.18.2
  • graphql version: 16.2.0
  • @graphql-codegen/client-preset version(s): 4.2.6
  • @graphql-codegen/visitor-plugin-common version(s): 2.13.1

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

Copy link

changeset-bot bot commented Jun 21, 2024

🦋 Changeset detected

Latest commit: 049b722

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@graphql-codegen/visitor-plugin-common Patch
@graphql-codegen/typescript-document-nodes Patch
@graphql-codegen/gql-tag-operations Patch
@graphql-codegen/typescript-operations Patch
@graphql-codegen/typescript-resolvers Patch
@graphql-codegen/typed-document-node Patch
@graphql-codegen/typescript Patch
@graphql-codegen/graphql-modules-preset Patch
@graphql-codegen/client-preset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vhfmag vhfmag changed the title feat: Pre-compute ClientSideBaseVisitor's fragmentsGraph Only compute ClientSideBaseVisitor's fragmentsGraph once, at instantiation time Jun 21, 2024
@n1ru4l n1ru4l merged commit 14ce39e into dotansimha:master Jun 24, 2024
18 checks passed
@vhfmag vhfmag deleted the perf-improvement branch June 24, 2024 16:18
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