Skip to content

Commit 467f41f

Browse files
committed
Load vnode.nodeName only once.
Since idiff is invoked on all kinds of virtual nodes, the property access vnode.nodeName is usually megamorphic in any realistic workload, so it's better for the JS engine to load the property only once. Also apply the String constructor only once to the vnode.nodeName, because the String constructor can have arbitrary side-effects (since it can call out to Symbol.toPrimitive, valueOf or toString), and thus requires magic on the engines' side to optimize this away, which doesn't always kick in (and is costly).
1 parent 9001436 commit 467f41f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/vdom/diff.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,20 @@ function idiff(dom, vnode, context, mountAll, componentRoot) {
9494

9595

9696
// If the VNode represents a Component, perform a component diff:
97-
if (typeof vnode.nodeName==='function') {
97+
let vnodeName = vnode.nodeName;
98+
if (typeof vnodeName==='function') {
9899
return buildComponentFromVNode(dom, vnode, context, mountAll);
99100
}
100101

101102

102103
// Tracks entering and exiting SVG namespace when descending through the tree.
103-
isSvgMode = vnode.nodeName==='svg' ? true : vnode.nodeName==='foreignObject' ? false : isSvgMode;
104+
isSvgMode = vnodeName==='svg' ? true : vnodeName==='foreignObject' ? false : isSvgMode;
104105

105106

106107
// If there's no existing element or it's the wrong type, create a new one:
107-
if (!dom || !isNamedNode(dom, String(vnode.nodeName))) {
108-
out = createNode(String(vnode.nodeName), isSvgMode);
108+
vnodeName = String(vnodeName);
109+
if (!dom || !isNamedNode(dom, vnodeName)) {
110+
out = createNode(vnodeName, isSvgMode);
109111

110112
if (dom) {
111113
// move children into the replacement node

0 commit comments

Comments
 (0)