-
-
Notifications
You must be signed in to change notification settings - Fork 752
feat: implement module.generator.json.JSONParse
#9666
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
feat: implement module.generator.json.JSONParse
#9666
Conversation
For large `.json` modules, webpack will generate `JSON.parse` by default for better performance. But there are some circumstances that `JSON.parse` is not a good choice (e.g.: when doing AOT compilation). Thus, a new generator option `module.generator.json.JSONParse` is added to disable generating `JSON.parse` for `.json` module. The default value is kept as `true` and can be opt-out by custom rules. This is a port of webpack/webpack#19320.
✅ Deploy Preview for rspack canceled.Built without sensitive environment variables
|
CodSpeed Performance ReportMerging #9666 will not alter performanceComparing 🎉 Hooray!
|
KuSh
left a comment
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.
Why not integrating associated webpack tests to the suite?
packages/rspack-test-tools/tests/configCases/json/generator-json-parse-false/index.js
Show resolved
Hide resolved
<!-- Thank you for submitting a pull request! We appreciate the time and effort you have invested in making these changes. Please ensure that you provide enough information to allow others to review your pull request. Upon submission, your pull request will be automatically assigned with reviewers. If you want to learn more about contributing to this project, please visit: https://github.com/lynx-family/lynx-stack/blob/main/CONTRIBUTING.md. --> ## Summary <!-- Can you explain the reasoning behind implementing this change? What problem or issue does this pull request resolve? --> <!-- It would be helpful if you could provide any relevant context, such as GitHub issues or related discussions. --> In web-infra-dev/rspack#9666, we added `module.generator.json.JSONParse` and set `JSONParse: false` for the main thread only to let AOT compilation speed up performance. However, different `JSONParse` configurations in the main thread and the background thread will prevent `extractStr` from working properly. In this PR, when `extractStr` is enabled, we should set `JSONParse` to `false` in both the main and background threads. ## Checklist <!--- Check and mark with an "x" --> - [x] Tests updated (or not required). - [ ] Documentation updated (or not required). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for the `extractStr` feature to improve handling of large JSON data. * **Bug Fixes** * Adjusted JSON processing rules to ensure correct behavior when `extractStr` is enabled or disabled. * **Tests** * Enhanced and added tests to verify JSON generator rule behavior across different plugin configurations and layers. * **Documentation** * Updated documentation to reflect the new feature and changes in behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
For large
.jsonmodules, webpack will generateJSON.parseby default forbetter performance. But there are some circumstances that
JSON.parseis not agood choice (e.g.: when doing AOT compilation).
Thus, a new generator option
module.generator.json.JSONParseis added todisable generating
JSON.parsefor.jsonmodule.The default value is kept as
trueand can be opt-out by custom rules.This is a port of webpack/webpack#19320.
Checklist