[performance] use JSON.parse(jsonSource) for JSON modules #9349
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-loader
module: