Fix a performance issue with JSON schema generation #11249
Merged
+39
−33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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