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

perf(gatsby): add a way to skip tracking inline objects #38805

Merged

Conversation

axe312ger
Copy link
Collaborator

Description

While upgrading gatsby-source-contentful to its new version, we figured out that Gatsby is parsing JSON and Rich Text fields for references, while the plugin does handle these on its own.

In discussion with @pieh, we decided to implement a flag into Gatsby, which prevents nodes from being parsed for trackable inline objects. This is a huge performance improvement for the new gatsby-source-contentful version, while potentially providing a performance improvement to all other plugins that implement external data and/or handle references on their own.

Documentation

Nodes will get an additional, optional internal boolean property: node.internal.dontTrackInlineObjects.

By default, none of Gatsbys behavior will change. Plugin developers and users implementing their own node types have to opt into this features manually.

Tests

@todo this PR still lacks tests

Related Issues

#30855

@axe312ger axe312ger added topic: performance Related to runtime & build performance topic: source-contentful Related to Gatsby's integration with Contentful topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) labels Jan 10, 2024
@axe312ger axe312ger requested a review from pieh January 10, 2024 10:54
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 10, 2024
@@ -34,6 34,8 @@ export {

export * from "gatsby-script"

export { IGatsbyResolverContext } from "./src/schema/type-definitions"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would guess we can skip this and I overlooked an already exported type for https://github.com/gatsbyjs/gatsby/pull/38805/files#diff-2a342b3e927ced0bfb4d19fe7f56ef73e0f08094f83526aaccc252d29af11870R44

🤔

Copy link
Contributor

@pieh pieh Feb 20, 2024

Choose a reason for hiding this comment

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

We don't really have good types for schema customization - most of it is ... any 🙈 so this is fine

@pieh pieh removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 10, 2024
@pieh
Copy link
Contributor

pieh commented Jan 10, 2024

Minor NIT is we probably shouldn't use dontX in internal field names - it made some sense in our initial conversation when we considered graphql directive (@dontX similar to @dontInfer), but when talking about raw nodes - we probably should just say trackInlineObjects: false and do explicit checks (if (node.internal.trackInlineObjects === false)) (as it would be falsy by default)

EDIT: this can stay as-is for now, while I gather feedback from other folks (just to avoid busy work with unnecessary renames in case we would have to drop this idea alltogether) - so this can wait before being addressed (and just in case I can do that as well later on)

@pieh pieh changed the title Feat/Perf: don't track inline objects perf(gatsby): add a way to skip tracking inline objects Jan 10, 2024
id: CODES.GatsbyPluginMissing,
context: {
// TODO update message to reflect the actual version with track-inline-object-opt-out support
sourceMessage: `Used gatsby version is too old and doesn't support required features. Please update to gatsby@>=5.X.0`,
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need to be updated before the release once it's clear that Gatsby Version that will contain the addition.

For now it will mean that users will have to use gatsby@ctf-next (once new wave of canary is released that include this change) - so maybe temporarily we can use that version there whatever that will end up being?

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

Thanks for the new toggle!

@axe312ger axe312ger merged commit 1ce2026 into feat/contentful-schema-generation Feb 29, 2024
32 of 33 checks passed
@axe312ger axe312ger deleted the feat/dont-track-inline-objects branch February 29, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) topic: performance Related to runtime & build performance topic: source-contentful Related to Gatsby's integration with Contentful
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants