Skip to content

Conversation

@colinaaa
Copy link
Collaborator

Summary

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.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

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.
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Mar 13, 2025
@netlify
Copy link

netlify bot commented Mar 13, 2025

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit a69dabb
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/67d38f27031c2d00085ce5bc

@colinaaa colinaaa marked this pull request as ready for review March 13, 2025 16:10
@colinaaa colinaaa requested review from ahabhgk and h-a-n-a March 13, 2025 16:11
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 13, 2025

CodSpeed Performance Report

Merging #9666 will not alter performance

Comparing colinaaa:colin/0313/json-generator (a69dabb) with main (09ac9ef)

🎉 Hooray! codspeed-rust just leveled up to 2.7.2!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 8 untouched benchmarks

Copy link
Contributor

@KuSh KuSh left a 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?

ahabhgk
ahabhgk previously approved these changes Mar 14, 2025
@ahabhgk ahabhgk merged commit 396ce92 into web-infra-dev:main Mar 14, 2025
31 checks passed
github-merge-queue bot pushed a commit to lynx-family/lynx-stack that referenced this pull request Jul 15, 2025
<!--
  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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants