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

refactor: Improve type inference performance of hot-path that computes fragment spreads #159

Merged
merged 9 commits into from
Mar 22, 2024

Conversation

kitten
Copy link
Member

@kitten kitten commented Mar 22, 2024

Summary

This aggressively optimises getFragmentsOfDocuments (previously named getFragmentsOfDocumentsRec).

In a typical codebase that uses fragment composition properly, there's only so many documents that are in any given hot-path of TypeScript's type checker on evaluation. While we're constrained by wanting to output the resulting TadaDocumentNode and its result shape — i.e. not wanting TypeScript to evaluate documents lazily on type hint output — the getFragmentsOfDocumentsRec was having a larger impact on performance than expected.

When applied, this PR refactors how fragments are recognised and how we convert the array of fragments, passed to graphql(), to a dictionary object.

Set of changes

  • Add FragmentShape and rename makeDefinitionDecoration to DefinitionDecoration
  • Remove result constraints from DocumentDecoration
  • Apply FragmentShape to API functions to pre-constrain their types
  • Refactor getFragmentsOfDocuments to be a non-recursive type

Copy link

changeset-bot bot commented Mar 22, 2024

🦋 Changeset detected

Latest commit: a7f1882

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

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

@kitten kitten changed the title Refactor/definition decorations refactor: Improve type inference performance of hot-path that computes fragment spreads Mar 22, 2024
@kitten kitten enabled auto-merge (squash) March 22, 2024 13:51
@kitten kitten merged commit 15d55c9 into main Mar 22, 2024
2 checks passed
@kitten kitten deleted the refactor/definition-decorations branch March 22, 2024 13:52
@github-actions github-actions bot mentioned this pull request Mar 22, 2024
@kitten kitten added this to the Are We Fast Yet? milestone Mar 22, 2024
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.

None yet

2 participants