Skip to content

Commit

Permalink
Some byte improvements (#4321)
Browse files Browse the repository at this point in the history
* save bytes during event registration

* test performance improvement (does increase bytes)

* optimize undefined setting

* minor saving

* undo perf to see byte impact
  • Loading branch information
JoviDeCroock authored Mar 25, 2024
1 parent 8759dad commit d3d57db
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
7 changes: 3 additions & 4 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,20 @@ export function getDomSibling(vnode, childIndex) {
function renderComponent(component) {
let oldVNode = component._vnode,
oldDom = oldVNode._dom,
parentDom = component._parentDom,
commitQueue = [],
refQueue = [];

if (parentDom) {
if (component._parentDom) {
const newVNode = assign({}, oldVNode);
newVNode._original = oldVNode._original + 1;
if (options.vnode) options.vnode(newVNode);

diff(
parentDom,
component._parentDom,
newVNode,
oldVNode,
component._globalContext,
parentDom.ownerSVGElement !== undefined,
component._parentDom.ownerSVGElement !== undefined,
oldVNode._flags & MODE_HYDRATE ? [oldDom] : null,
commitQueue,
oldDom == null ? getDomSibling(oldVNode) : oldDom,
Expand Down
5 changes: 2 additions & 3 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ export function unmount(vnode, parentVNode, skipRemove) {
}

r.base = r._parentDom = null;
vnode._component = undefined;
}

if ((r = vnode._children)) {
Expand All @@ -588,7 +587,7 @@ export function unmount(vnode, parentVNode, skipRemove) {
unmount(
r[i],
parentVNode,
skipRemove || typeof vnode.type !== 'function'
skipRemove || typeof vnode.type != 'function'
);
}
}
Expand All @@ -600,7 +599,7 @@ export function unmount(vnode, parentVNode, skipRemove) {

// Must be set to `undefined` to properly clean up `_nextDom`
// for which `null` is a valid value. See comment in `create-element.js`
vnode._parent = vnode._dom = vnode._nextDom = undefined;
vnode._component = vnode._parent = vnode._dom = vnode._nextDom = undefined;
}

/** The `.render()` method for a PFC backing instance. */
Expand Down
35 changes: 20 additions & 15 deletions src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,20 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
if (value) {
if (!oldValue) {
value._attached = eventClock;

const handler = useCapture ? eventProxyCapture : eventProxy;
dom.addEventListener(name, handler, useCapture);
dom.addEventListener(
name,
useCapture ? eventProxyCapture : eventProxy,
useCapture
);
} else {
value._attached = oldValue._attached;
}
} else {
const handler = useCapture ? eventProxyCapture : eventProxy;
dom.removeEventListener(name, handler, useCapture);
dom.removeEventListener(
name,
useCapture ? eventProxyCapture : eventProxy,
useCapture
);
}
} else {
if (isSvg) {
Expand All @@ -99,18 +104,18 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
// - className --> class
name = name.replace(/xlink(H|:h)/, 'h').replace(/sName$/, 's');
} else if (
name !== 'width' &&
name !== 'height' &&
name !== 'href' &&
name !== 'list' &&
name !== 'form' &&
name != 'width' &&
name != 'height' &&
name != 'href' &&
name != 'list' &&
name != 'form' &&
// Default value in browsers is `-1` and an empty string is
// cast to `0` instead
name !== 'tabIndex' &&
name !== 'download' &&
name !== 'rowSpan' &&
name !== 'colSpan' &&
name !== 'role' &&
name != 'tabIndex' &&
name != 'download' &&
name != 'rowSpan' &&
name != 'colSpan' &&
name != 'role' &&
name in dom
) {
try {
Expand Down

0 comments on commit d3d57db

Please sign in to comment.