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
Sortable set #5083
Sortable set #5083
Conversation
use SortableSet to keep "_modules" sorted
use SortableSet to keep "_chunks" sorted
fix tests that was falsy - per default chunks are flagged as sorted in module however this only holds true as they are initialized empty. Concatenated module however has initial modules and therefore is not guaranteed to be ordered, the flags should therfor be false. Using SortedSet fixes this as a sideeffect
lib/Chunk.js
Outdated
class Chunk { | ||
|
||
static sortById(a, b) { |
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 making this methods public? What was wrong with the original way, which hides them?
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.
Initially I wanted to flip them, so sortByXXX
was in Module
and Chunk
would use Module.sortByXXX
to sort its Modules.
As Module should know how to sort modules, not Chunk.
However node and circular dependencies let me down and so this is a left over of that approach, happy to make them private again, but I'd rather find a solution for the intial idea. :D
lib/util/SortableSet.js
Outdated
* @returns {void} | ||
*/ | ||
sortWith(sortFn) { | ||
const sortedArray = Array.from(this).sort(sortFn); |
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.
The original impl checked if the set was already sorted before sorting. The new SortableSet should do the same. add
and clear
should be overriden to invalidate sorting. Best store the current active sortFn.
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.
yeah, I wasn't sure if this approach is ok and if I wanted to shadow as little as possible from the initial set (: happy to add some logic there
@@ -19,7 +19,7 @@ Child | |||
[0] (webpack)/test/statsCases/scope-hoisting-multi/common_lazy_shared.js 25 bytes {0} {1} {2} [built] | |||
[1] (webpack)/test/statsCases/scope-hoisting-multi/vendor.js 25 bytes {5} [built] | |||
ModuleConcatenation (inner): module is an entrypoint | |||
[2] (webpack)/test/statsCases/scope-hoisting-multi/common.js + 1 modules 62 bytes {4} {3} [built] | |||
[2] (webpack)/test/statsCases/scope-hoisting-multi/common.js + 1 modules 62 bytes {3} {4} [built] |
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.
This should not happen?
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.
see: bd8c6cf
fix tests that was falsy - per default chunks are flagged as sorted in module
however this only holds true as they are initialized empty. Concatenated module however
has initial modules and therefore is not guaranteed to be ordered, the flags should therfor be false.
Using SortedSet fixes this as a sideeffect
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.
Ah okey. 👍
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.
It seem to be different again...
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.
ha yea, it tries to use the sort method from Module
but its no longer exposed...
meh, i'd love to just have a compareBy
method on them :P maybe in another PR if thats ok :D
lib/util/SortableSet.js
Outdated
super(initialIterable); | ||
this._sortFn = defaultSort; | ||
this._lastActiveSortFn = null; | ||
this._isSorted = false; |
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.
_isSorted
is redundant to _lastActiveSortFn
. _isSorted === !!_lastActiveSortFn
.
=> _isSorted
can be removed.
lib/util/SortableSet.js
Outdated
/** | ||
* @returns {void} | ||
*/ | ||
clear() { |
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.
clear can be removed, as an empty set is always sorted.
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.
true :D
lib/util/SortableSet.js
Outdated
* @returns {void} | ||
*/ | ||
sortWith(sortFn) { | ||
if(this._isSorted && sortFn === this._lastActiveSortFn) { |
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.
We could skip sorting if this.size === 0
. This avoids creating a new empty array below.
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.
👍
@@ -19,7 +19,7 @@ Child | |||
[0] (webpack)/test/statsCases/scope-hoisting-multi/common_lazy_shared.js 25 bytes {0} {1} {2} [built] | |||
[1] (webpack)/test/statsCases/scope-hoisting-multi/vendor.js 25 bytes {5} [built] | |||
ModuleConcatenation (inner): module is an entrypoint | |||
[2] (webpack)/test/statsCases/scope-hoisting-multi/common.js + 1 modules 62 bytes {4} {3} [built] | |||
[2] (webpack)/test/statsCases/scope-hoisting-multi/common.js + 1 modules 62 bytes {3} {4} [built] |
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.
Ah okey. 👍
- remove unnecessary _isSorted flag - remove clear-override as an empty set is "sorted" - early return on empty sets
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
Thanks |
What kind of change does this PR introduce?
feature
Did you add tests for your changes?
tested through existing code
If relevant, link to documentation update:
N/A
Summary
Introduce a "SortableSet" Collection that abstracts the sorting out of the responsibility of Module/Chunk
Does this PR introduce a breaking change?
No
Other information
Per default
_chunks
are flagged as sorted in Module, however, this only holds true as they are initialized empty.Concatenated Module, however, has initial modules and therefore is not guaranteed to be ordered, the flags should, therefore, be false. Using SortedSet fixes this as a side effect.