Skip to content
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

Avoid leaking internal vnodes #3106

Merged
merged 2 commits into from
Oct 12, 2021
Merged

Conversation

developit
Copy link
Member

We started calling options.vnode() for internal "text" VNodes and copied VNodes at some point, as best as I can tell it was unintentional. We don't officially support the Text VNode shape, and copied VNodes shouldn't be passed through options.vnode again because they've already been processed.

This should be good for performance, though it likely won't show up in benchmarks because it primarily affects preact/compat.

We started calling `options.vnode()` for internal "text" VNodes and copied VNodes at some point, as best as I can tell it was unintentional. We don't officially support the Text VNode shape, and copied VNodes shouldn't be passed through `options.vnode` again because they've already been processed.

This should be good for performance, though it likely won't show up in benchmarks because it primarily affects `preact/compat`.
@github-actions
Copy link

github-actions bot commented Apr 10, 2021

📊 Tachometer Benchmark Results

Summary

duration

  • 02_replace1k: unsure 🔍 -1% - +2% (-1.16ms - +2.42ms)
    preact-local vs preact-master
  • 03_update10th1k_x16: unsure 🔍 -3% - +5% (-1.12ms - +1.52ms)
    preact-local vs preact-master
  • 07_create10k: unsure 🔍 -0% - +1% (-3.71ms - +9.64ms)
    preact-local vs preact-master
  • filter_list: unsure 🔍 -3% - +8% (-0.61ms - +1.88ms)
    preact-local vs preact-master
  • hydrate1k: unsure 🔍 -4% - +2% (-7.11ms - +4.09ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -4% - +5% (-1.54ms - +1.65ms)
    preact-local vs preact-master
  • text_update: unsure 🔍 -3% - +0% (-0.08ms - +0.00ms)
    preact-local vs preact-master

usedJSHeapSize

  • 02_replace1k: unsure 🔍 -0% - +0% (-0.01ms - +0.01ms)
    preact-local vs preact-master
  • 03_update10th1k_x16: unsure 🔍 -0% - +0% (-0.00ms - +0.01ms)
    preact-local vs preact-master
  • 07_create10k: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-master
  • filter_list: unsure 🔍 -0% - +0% (-0.01ms - +0.00ms)
    preact-local vs preact-master
  • hydrate1k: unsure 🔍 -0% - +2% (-0.01ms - +0.09ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-master
  • text_update: unsure 🔍 +0% - +0% (+0.00ms - +0.00ms)
    preact-local vs preact-master

Results

02_replace1k

duration

VersionAvg timevs preact-mastervs preact-local
preact-master131.10ms - 133.45ms-unsure 🔍
-2% - +1%
-2.42ms - +1.16ms
preact-local131.55ms - 134.26msunsure 🔍
-1% - +2%
-1.16ms - +2.42ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master3.45ms - 3.46ms-unsure 🔍
-0% - +0%
-0.01ms - +0.01ms
preact-local3.45ms - 3.46msunsure 🔍
-0% - +0%
-0.01ms - +0.01ms
-

run-warmup-0

VersionAvg timevs preact-mastervs preact-local
preact-master47.55ms - 49.50ms-unsure 🔍
-2% - +5%
-0.76ms - +2.34ms
preact-local46.54ms - 48.94msunsure 🔍
-5% - +2%
-2.34ms - +0.76ms
-

run-warmup-1

VersionAvg timevs preact-mastervs preact-local
preact-master83.04ms - 85.60ms-unsure 🔍
-2% - +2%
-2.09ms - +2.03ms
preact-local82.74ms - 85.96msunsure 🔍
-2% - +2%
-2.03ms - +2.09ms
-

run-warmup-2

VersionAvg timevs preact-mastervs preact-local
preact-master76.26ms - 83.00ms-unsure 🔍
-4% - +9%
-2.90ms - +6.79ms
preact-local74.20ms - 81.17msunsure 🔍
-8% - +4%
-6.79ms - +2.90ms
-

run-warmup-3

VersionAvg timevs preact-mastervs preact-local
preact-master52.73ms - 58.87ms-unsure 🔍
-12% - +3%
-7.20ms - +2.02ms
preact-local54.95ms - 61.83msunsure 🔍
-4% - +13%
-2.02ms - +7.20ms
-

run-warmup-4

VersionAvg timevs preact-mastervs preact-local
preact-master81.91ms - 84.38ms-unsure 🔍
-1% - +3%
-1.11ms - +2.44ms
preact-local81.20ms - 83.76msunsure 🔍
-3% - +1%
-2.44ms - +1.11ms
-

run-final

VersionAvg timevs preact-mastervs preact-local
preact-master49.66ms - 51.71ms-unsure 🔍
-4% - +2%
-2.01ms - +1.13ms
preact-local49.94ms - 52.30msunsure 🔍
-2% - +4%
-1.13ms - +2.01ms
-
03_update10th1k_x16

duration

VersionAvg timevs preact-mastervs preact-local
preact-master31.72ms - 33.57ms-unsure 🔍
-5% - +3%
-1.52ms - +1.12ms
preact-local31.91ms - 33.78msunsure 🔍
-3% - +5%
-1.12ms - +1.52ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master3.37ms - 3.37ms-unsure 🔍
-0% - +0%
-0.01ms - +0.00ms
preact-local3.37ms - 3.38msunsure 🔍
-0% - +0%
-0.00ms - +0.01ms
-
07_create10k

duration

VersionAvg timevs preact-mastervs preact-local
preact-master1252.82ms - 1260.46ms-unsure 🔍
-1% - +0%
-9.64ms - +3.71ms
preact-local1254.13ms - 1265.08msunsure 🔍
-0% - +1%
-3.71ms - +9.64ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master25.30ms - 25.30ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-local25.30ms - 25.30msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
filter_list

duration

VersionAvg timevs preact-mastervs preact-local
preact-master23.96ms - 25.64ms-unsure 🔍
-7% - +2%
-1.88ms - +0.61ms
preact-local24.52ms - 26.35msunsure 🔍
-3% - +8%
-0.61ms - +1.88ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master1.52ms - 1.52ms-unsure 🔍
-0% - +0%
-0.00ms - +0.01ms
preact-local1.52ms - 1.52msunsure 🔍
-0% - +0%
-0.01ms - +0.00ms
-
hydrate1k

duration

VersionAvg timevs preact-mastervs preact-local
preact-master158.15ms - 167.02ms-unsure 🔍
-3% - +4%
-4.09ms - +7.11ms
preact-local157.66ms - 164.49msunsure 🔍
-4% - +2%
-7.11ms - +4.09ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master6.02ms - 6.09ms-unsure 🔍
-1% - +0%
-0.09ms - +0.01ms
preact-local6.05ms - 6.13msunsure 🔍
-0% - +2%
-0.01ms - +0.09ms
-
many_updates

duration

VersionAvg timevs preact-mastervs preact-local
preact-master34.45ms - 36.76ms-unsure 🔍
-5% - +4%
-1.65ms - +1.54ms
preact-local34.55ms - 36.76msunsure 🔍
-4% - +5%
-1.54ms - +1.65ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master4.58ms - 4.59ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-local4.58ms - 4.59msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
text_update

duration

VersionAvg timevs preact-mastervs preact-local
preact-master2.85ms - 2.91ms-unsure 🔍
-0% - +3%
-0.00ms - +0.08ms
preact-local2.81ms - 2.87msunsure 🔍
-3% - +0%
-0.08ms - +0.00ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master0.76ms - 0.76ms-unsure 🔍
-0% - -0%
-0.00ms - -0.00ms
preact-local0.76ms - 0.76msunsure 🔍
+0% - +0%
+0.00ms - +0.00ms
-

tachometer-reporter-action v2 for Benchmarks

@coveralls
Copy link

coveralls commented Apr 10, 2021

Coverage Status

Coverage remained the same at 99.624% when pulling 6e0226d on avoid-leaking-internal-vnodes into 51bfe15 on master.

@github-actions
Copy link

github-actions bot commented Apr 10, 2021

Size Change: -3 B (0%)

Total Size: 42 kB

Filename Size Change
dist/preact.js 3.96 kB -2 B (0%)
dist/preact.umd.js 4.03 kB -1 B
ℹ️ View Unchanged
Filename Size Change
compat/dist/compat.js 3.44 kB 0 B
compat/dist/compat.module.js 3.42 kB 0 B
compat/dist/compat.umd.js 3.49 kB 0 B
debug/dist/debug.js 2.99 kB 0 B
debug/dist/debug.module.js 2.98 kB 0 B
debug/dist/debug.umd.js 3.07 kB 0 B
devtools/dist/devtools.js 232 B 0 B
devtools/dist/devtools.module.js 241 B 0 B
devtools/dist/devtools.umd.js 308 B 0 B
dist/preact.min.js 3.98 kB 0 B
dist/preact.module.js 3.98 kB 0 B
hooks/dist/hooks.js 1.13 kB 0 B
hooks/dist/hooks.module.js 1.14 kB 0 B
hooks/dist/hooks.umd.js 1.2 kB 0 B
jsx-runtime/dist/jsxRuntime.js 317 B 0 B
jsx-runtime/dist/jsxRuntime.module.js 327 B 0 B
jsx-runtime/dist/jsxRuntime.umd.js 395 B 0 B
test-utils/dist/testUtils.js 437 B 0 B
test-utils/dist/testUtils.module.js 439 B 0 B
test-utils/dist/testUtils.umd.js 515 B 0 B

compressed-size-action

@@ -78,7 +78,8 @@ export function createVNode(type, props, key, ref, original) {
_original: original == null ? ++options._vnodeId : original
};

if (options.vnode != null) options.vnode(vnode);
// Only invoke the vnode hook if this was *not* a direct copy:
if (original == null && options.vnode != null) options.vnode(vnode);
Copy link
Member

@JoviDeCroock JoviDeCroock Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern here becomes a bit prefresh-related, we'd break prefresh for ESM-runtimes like wmr, vite & snowpack. Consider the following VDOM-tree:

const Parent = () => <Child />

When we upate Child internally we assign a new type and call forceUpdate, now if we update Parent the reference will still contain a stale version of .type in _children[0] which means that it'll render the previous version of said functional node.

We'd have to change from this to something that gets all parent vnodes and updates their own child.type

Had a bit more thought about this and this would generally completely break it I think as we can't track vnodes anymore, so if a few setStates occur we would not have the right references possibly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Parent is invoked, it will call h(Child) and run options.vnode on that VNode - wouldn't that keep prefresh working?

@JoviDeCroock JoviDeCroock merged commit 9ae9f03 into master Oct 12, 2021
@JoviDeCroock JoviDeCroock deleted the avoid-leaking-internal-vnodes branch October 12, 2021 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants