Skip to content
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

Performance improvement #406

Merged
merged 2 commits into from Nov 5, 2019
Merged

Performance improvement #406

merged 2 commits into from Nov 5, 2019

Conversation

sokra
Copy link
Member

@sokra sokra commented Nov 1, 2019

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update
  • performance upgrade

Motivation / Use-Case

Sets don't allow duplicates, so checking for has is not necessary

webpack 5 makes these Sets lazy, which makes reading more expensive.
So only the watcher should read from these Sets, which is called after the compilation has finished,
so that doesn't contribute to build performance.

LazySets also have a addAll method, which allows to add an Iterable lazily (only iterated when LazySet is read)

Breaking Changes

No, webpack 4 compatibility is kept

Additional Info

Sets don't allow duplicates, so checking for `has` is not necessary

webpack 5 makes these Sets lazy, which makes reading more expensive.
So only the watcher should read from these Sets, which is called after the compilation has finished,
so that doesn't contribute to build performance.

LazySets also have a `addAll` method, which allows to add an Iterable lazily (only iterated when LazySet is read)
@codecov
Copy link

codecov bot commented Nov 1, 2019

Codecov Report

Merging #406 into master will decrease coverage by 0.03%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #406      +/-   ##
==========================================
- Coverage   94.88%   94.84%   -0.04%     
==========================================
  Files           9        9              
  Lines         293      291       -2     
  Branches       78       78              
==========================================
- Hits          278      276       -2     
  Misses         14       14              
  Partials        1        1
Impacted Files Coverage Δ
src/index.js 96.15% <66.66%> (-0.15%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5db376b...cdb3cbd. Read the comment docs.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@alexander-akait alexander-akait merged commit c546871 into master Nov 5, 2019
@alexander-akait alexander-akait deleted the perf/dependencies branch November 5, 2019 16:28
@jquense
Copy link

jquense commented Nov 21, 2019

This is breaking webpack4 for us. I think it's a bad interaction with some library using corejs, but interestingly if i log out addAll it's returning function addAll() { [native code] } which is a bit alarming. I cannot reproduce it in the repl tho!

FYI addAll is a proposed method for Set's so likely this test will fail if they are implemented https://github.com/tc39/proposal-collection-methods

@alexander-akait
Copy link
Member

@jquense it is custom webpack class and not related to corejs

@jquense
Copy link

jquense commented Nov 22, 2019

@evilebottnawi I realize that, the problem is that it checks if addAll is in the class, in webpack4 it is a Set, and that webpack 4 Set also has addAll that works differently. because some other library (I think) uses corejs which is polyfilling Set.addAll

@jquense
Copy link

jquense commented Nov 22, 2019

In other words checking 'addAll' in compilation.fileDependencies is not a safe check, because there is a proposal, and polyfill for a native addAll that works differently than LazySet.addAll. The code should probably duck type this differently

@alexander-akait
Copy link
Member

@jquense what idea do you have to fix it? Maybe instance of solve this?

@jquense
Copy link

jquense commented Nov 22, 2019

either instanceof or maybe add a static symbol to LazySet so you can typecheck like foo[Symbol.for('@@LazySet')] == true or maybe just check the constructor.name === 'LazySet'?

@alexander-akait
Copy link
Member

@jquense Can you send a PR?

@jquense
Copy link

jquense commented Dec 11, 2019

That would require i larger ecosystem change and i'm not sure what the desired approach would be. Generally happy to send PR's tho. @sokra should really be aware of this issue as well, b/c this test is likely in other places

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants