(fix) Use module ids for final render order#19184
(fix) Use module ids for final render order#19184alexander-akait merged 2 commits intowebpack:mainfrom
Conversation
|
For maintainers only:
|
|
Thanks |
|
This need to be solved differently. Sorting by module I'd basically puts modules in a kind of random order when deterministic module IDs is used. This hurts gzip compression quite a lot compared to ordered by identifier. By identifier puts modules with a similar path next to each other and that compresses much better. |
I'd expect the order to only meaningfully affect compressibility in unminified builds, though? The paths shouldn't appear in code in a minified build, so I don't see how sorting by identifier would help. The alternative we considered was to update the sort by identifier function to perform the same portabilization that the DeterministicModuleIdsPlugin does on the identifiers before comparing, but that's likely to hurt performance quite a bit, since even with a cache, it's a lot of lookups to add to the comparison. |
|
Compression is affected by the order as it depends on which modules are placed next to each other in the chunk. Gzip only has a certain context window to copy similar sequences and copying from nearby code is cheaper. Imagine you have a folder with 100 icon components that all lock exactly the same except for the icon path. Sorting by identifier places them all next to each other, which sorting by module id does not. |
|
@dmichon-msft @sokra What is our final solution, because the problem of non-deterministic builds on different OS also brings problems, previously, I received feedback quite often to pay attention to this issue. |
|
It seems that the issue is caused by file path across different OS. So can we
And I tested it locally using the repo mentioned in the issue above. |
|
It's not just the |
|
Could you provide additional examples or detailed clarify? I’m sorry, but I’m not fully understanding your idea. |
|
The identifier for Granted, the technically correct names would be |
|
Most likely the correct long-term solution here is that we should use for sorting the result of |
|
Most likely the correct long-term solution here is that we should use for sorting the result of |
Fixes #19141
Specifically, addresses determinism of sort order across platforms by leveraging the fact that a developer who desires stable output cross-platform will have already ensured that module ids are stable, so it necessarily follows that sorting by module id will result in a deterministic sort order.
What kind of change does this PR introduce?
bugfix
Did you add tests for your changes?
Added a unit test that verifies that Javascript modules are rendered in sorted order.
Does this PR introduce a breaking change?
The sort order of modules in rendered output will change, but a one-time alteration to that order is no different than changing a salt value.
What needs to be documented once your changes are merged?