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

Fix a performance issue with JSON schema generation #11249

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

markgaze
Copy link
Contributor

@markgaze markgaze commented Jun 13, 2024

Changes

I have a large number of items in my content collections and I've noticed a considerable slowness when starting the dev server, having looked into it (with --verbose), I noticed that the JSON schema files were being changed repeatedly which made the HMR spend approximately 90ms reloading it. With a lot of content files, this quickly adds up and made my startup times approach a minute in some cases 🙈

This PR changes the behaviour so that the JSON schema is only generated once rather than in the for loop like it was before, I can't think of any reason that it needed to be in that for loop but other people may know better than me!

Testing

I've tested this change in the project that was having the performance issue and it only generates the JSON schemas once and the dev server starts instantly, as it did before.

I also ran the unit tests locally and they still generate the same JSON schema files

I haven't added a test for this scenario, as it could be quite difficult to prove that it was slow but isn't now but I'm happy to look into it, if it's of value!

If nothing else, I could throw together a StackBlitz example that shows the issue, if needs be 🙂

Docs

Nothing changes for the end user, so no new docs required

Copy link

changeset-bot bot commented Jun 13, 2024

🦋 Changeset detected

Latest commit: 4e0bdef

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jun 13, 2024
@markgaze markgaze force-pushed the json-schema-efficiency branch 2 times, most recently from 961b434 to 02ae167 Compare June 13, 2024 15:13
@ematipico ematipico merged commit de60c69 into withastro:main Jun 14, 2024
13 checks passed
@markgaze markgaze deleted the json-schema-efficiency branch June 14, 2024 10:39
@astrobot-houston astrobot-houston mentioned this pull request Jun 14, 2024
`An error was encountered while creating the JSON schema for the ${entryKey} entry in ${collectionKey} collection. Proceeding without it. Error: ${err}`
);
}
dataTypesStr += `};\n`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this line shouldn't be moved to here. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. My bad, sorry! I was having some formatting issues in VS Code and I think this happened when I was trying to fix it. I'll see if I can add some tests around this to make sure it doesn't happen again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants