-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
🦋 Changeset detectedLatest 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 |
961b434
to
02ae167
Compare
02ae167
to
4e0bdef
Compare
`An error was encountered while creating the JSON schema for the ${entryKey} entry in ${collectionKey} collection. Proceeding without it. Error: ${err}` | ||
); | ||
} | ||
dataTypesStr += `};\n`; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
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 thatfor
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