-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
More specific if conditions lead to ~10% faster render. #610
Changes from all commits
4ee46be
2098502
b8e367f
052a1e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,10 +187,10 @@ function innerDiffNode(dom, vchildren, context, mountAll, absorb) { | |
min = 0, | ||
len = originalChildren.length, | ||
childrenLen = 0, | ||
vlen = vchildren && vchildren.length, | ||
vlen = vchildren ? vchildren.length : 0, | ||
j, c, vchild, child; | ||
|
||
if (len) { | ||
if (len!==0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While you're making things more explicit, don't you really mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strict equality should be faster than a comparison since it does no casting, but @bmeurer is far more knowledgeable on that than I am. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand now. You're focusing on perf over explicit code intent. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the |
||
for (let i=0; i<len; i++) { | ||
let child = originalChildren[i], | ||
props = child[ATTR_KEY], | ||
|
@@ -205,7 +205,7 @@ function innerDiffNode(dom, vchildren, context, mountAll, absorb) { | |
} | ||
} | ||
|
||
if (vlen) { | ||
if (vlen!==0) { | ||
for (let i=0; i<vlen; i++) { | ||
vchild = vchildren[i]; | ||
child = null; | ||
|
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 is the real culprit, as now vlen will always be a Number (and known to the compiler as such). You could probably go one step further and avoid the ToBoolean on
vchildren
as well by writing something likevlen = (vchildren !== undefined) ? vchildren.length : 0
if that matches the contract.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.
Thanks for your insights, @bmeurer!
Would an
undefined
default (e.g.vlen = vchildren ? vchildren.length : undefined
) be less optimal for the compiler than the default of0
? Same question fornull
. Thanks!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.
undefined
ornull
are less ideal than0
here, as the compiler needs to choose a tagged representation that can represents bothundefined
/null
as well as numbers. If you use only (small integer) numbers, then the optimizing compilers in VMs can usually pick the ideal unboxed Word/Word32 representation.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.
Got it. Thank you!