[performance] use JSON.parse(jsonSource) for JSON modules#9349
Merged
sokra merged 2 commits intowebpack:masterfrom Jul 2, 2019
Merged
[performance] use JSON.parse(jsonSource) for JSON modules#9349sokra merged 2 commits intowebpack:masterfrom
sokra merged 2 commits intowebpack:masterfrom
Conversation
https://v8.dev/blog/cost-of-javascript-2019 > As long as the JSON string is only evaluated once, the JSON.parse approach is much faster compared to the JavaScript object literal, especially for cold loads.
Contributor
|
For maintainers only:
|
Contributor
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
sokra
approved these changes
Jul 2, 2019
Member
|
Thanks |
sgratzl
added a commit
to cmu-delphi/www-covidcast
that referenced
this pull request
Jan 5, 2021
This reverts commit 306b61d. see webpack/webpack#9349
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Use
JSON.parse(jsonSource)for JSON modules instead of object literals.This is an implementation of the idea that comes from https://v8.dev/blog/cost-of-javascript-2019
The article is written by the V8 team, but it should be true for all the JavaScript engines because JSON is much simpler than JavaScript.
NOTE: I didn't add an option to enable/disable this feature because users can easily use json-loader that converts JSON to JavaScript.
What kind of change does this PR introduce?
A performance optimization.
Did you add tests for your changes?
No. This PR does not change the behavior, but I've tested it on my production code that boosts ~20% of "loading" time on Chrome 75 in my bundle.js that includes over 1MiB of JSON objects.
Does this PR introduce a breaking change?
No.
What needs to be documented once your changes are merged?
No. It's just an implementation detail.
FYI you can try the implementation without patching webpack:
(added on 2019/07/09)
To disable this feature in order to, for example, measure the performance, use the good old
json-loadermodule: