Avoid deoptimization in generateCSS()#204
Merged
Merged
Conversation
I was profiling the css() function and Chrome raised a flag on this function: > Not optimized: Bad value context for arguments value More info on this warning: GoogleChrome/devtools-docs#53 (comment) Looking at the warning and the compiled version of this code, it seems to do some things with `arguments` when using the default values here, which is causing this deoptimization. ```js var selectorHandlers = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; var stringHandlers = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; var useImportant = arguments.length <= 4 || arguments[4] === undefined ? true : arguments[4]; ``` By removing the default values for the arguments, the deoptimization disappears. I thought about adding logic that would provide values for these arguments if they aren't defined, but since the only thing that relies on that is tests I decided to just update the tests to always pass all of the arguments. In my benchmark, this does not seem to make much of a difference but it still seems like a good idea to avoid things that the browser tells us is deoptimized.
xymostech
approved these changes
Mar 6, 2017
Contributor
xymostech
left a comment
There was a problem hiding this comment.
Interesting! Changes LGTM. Does this mean that we shouldn't use default argument values anywhere?
Collaborator
Author
|
Possibly, or maybe the Babel transform can be modified in a way that avoids this? In any case, it was hard for me to see what the real world performance impact of this actually is. Maybe @twokul or @paulirish can point us in the right direction here? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I was profiling the css() function and Chrome raised a flag on this
function:
More info on this warning:
GoogleChrome/devtools-docs#53 (comment)
Looking at the warning and the compiled version of this code, it seems
to do some things with
argumentswhen using the default valueshere, which is causing this deoptimization.
By removing the default values for the arguments, the deoptimization
disappears. I thought about adding logic that would provide values for
these arguments if they aren't defined, but since the only thing that
relies on that is tests I decided to just update the tests to always
pass all of the arguments.
In my benchmark, this does not seem to make much of a difference but it
still seems like a good idea to avoid things that the browser tells us
is deoptimized.