-
Notifications
You must be signed in to change notification settings - Fork 394
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
DRY up tappable code for applyPlugins. #34
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Without knowing a lot about this code and how it's being used, I'd suspect that this
this._plugins[name]
is not going to be monomorphic (i.e.name
will be different and probablythis._plugins
too). So repeating this load is going to be the expensive part.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.
@bmeurer here is just a few examples of apply plugins being used in two separate classes that extend Tapable.
https://github.com/webpack/webpack/blob/990563f9a2b3fb3e817b7e1b9d6841bcd1eaa51e/lib/Compilation.js#L48-L676
https://github.com/webpack/webpack/blob/990563f9a2b3fb3e817b7e1b9d6841bcd1eaa51e/lib/Parser.js#L1045-L1141
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.
Ok, based on this benchmark, I'd strongly suggest to go for
F.p.apply
and rest parameters instead, as indicated by the results for Chrome Canary: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.
So I was curious about Chrome Stable (V8 6.0.286.52, same as Node 8.3, and this code is running on Node) and the results are bit different:
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.
Jep, just checked Chrome 61 (which is what Node 8 will eventually be based on in the end), and same picture there:
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.
FYI: Ran this gist with latest Node 8.3.0 locally and I do indeed see results similar to what I observed with Canary:
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.
PR updated with optimized version
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.
I see to performance benefit for the method with variable number of arguments.
But I don't see the benefit for the methods with fixed number of arguments (i. e.
applyPlugins2
). They are manually optimized for a specific number of arguments. Most "hot" hooks use them.Anyway, I would love to take a more radical approach. This whole package is a bit old. What about a new major version with more performance and more features.
arguments
, compile fixed arguments function.new Function(`function x(${args}) ...`)
compiler.plugin("before-run", ...)
compiler.hooks.beforeRun(...)
to allow have typings for these hooks.compiler.hooks.beforeRun("HotModuleReplacementPlugin", () => ...)
hooks.beforeRun({ name: ..., before: "HotModuleReplacementPlugin" }, () => ...)
hooks.beforeRun.intercept(...)
plugin(...)
method can be provided for backward compatibility for plugins.applyPluginsXXX
methods can also be offered for backward compatibility, but trigger a deprecation.plugin
orapplyPluginsXXX
automatically register a compat hook which handle 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.
I created a new issue for this: #35