fix: keep renderModule order consistent#19867
Conversation
CodSpeed Performance ReportMerging #19867 will degrade performances by 46.05%Comparing Summary
Benchmarks breakdown
|
This comment was marked as outdated.
This comment was marked as outdated.
|
@JSerFeng I think your suggestion of "sort modules first before render" is a good one. However, after internal discussions, the team is more inclined to use the approach of import { v as v_xxxx }. This is because import "as" syntax is analyzable by all bundlers(Though it’s a bit lengthy and clunky 😅). While this solution cannot completely avoid naming conflicts in the chunk scope, the probability of such conflicts is negligible. import { v as __WEBPACK_EXTERNAL_MODULE_externals0_v__ } from "externals0";
import { v as __WEBPACK_EXTERNAL_MODULE_externals1_v__ } from "externals1"; |
|
@JSerFeng In future we will think about it more deeply (maybe with some design changes), we still want to generate as small and analyzable code as possible, but we want to make a release soon, so current changes fix almost all cases |
Yeah it's okay, previous external namespace symbol has little chance to conflicts as well. We've thought of this solution as well, the main reason Rspack currently not doing this is because Rspack is heading to a completely new esm output format implementation As for three shaking, currently the original namespace importing external is also analyzable by popular bundler, I change the render of external module mainly because Rslib wants the more pretty output. It's totally fine to fix this for now ❤️ |
What kind of change does this PR introduce?
Fixes #19861 (comment)
The order of Compilation.modules depends on when module.build finishes, which leads to unstable ordering and different results during render.
We could consider changing Compilation.modules to a SortableSet to make the order deterministic.
Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
No
What needs to be documented once your changes are merged?
No