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

Always clear _nextDom field on VNodes #4166

Merged
merged 5 commits into from
Oct 24, 2023
Merged

Always clear _nextDom field on VNodes #4166

merged 5 commits into from
Oct 24, 2023

Conversation

andrewiggins
Copy link
Member

While working on #4162, I discovered some situations where we fail to clear _nextDom meaning we hang on to possibly detached HTMLElements. This fixes a bug in diffChildren so we always clear _nextDom for components/fragments and clears _nextDom in commitRoot since root VNodes don't necessarily go through diffChildren to get cleared.

I've added some code to teardown to run through the VNode tree and verify that _nextDom is null/undefined.

I also found a reference to _nextDom in Suspense. However in all of our tests it is null so I replaced that call to insertBefore(node, null) with a call to appendChild.

_nextDom was always null/undefined in our test suite in this code path so replacing it with a direct call to appendChild.
@github-actions
Copy link

github-actions bot commented Oct 24, 2023

📊 Tachometer Benchmark Results

Summary

duration

  • 02_replace1k: unsure 🔍 -1% - +1% (-1.40ms - +0.86ms)
    preact-local vs preact-main
  • 03_update10th1k_x16: unsure 🔍 -3% - +4% (-0.90ms - +1.50ms)
    preact-local vs preact-main
  • 07_create10k: unsure 🔍 -2% - +1% (-20.54ms - +14.49ms)
    preact-local vs preact-main
  • filter_list: unsure 🔍 -1% - +0% (-0.26ms - +0.05ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -0% - +4% (-0.59ms - +7.04ms)
    preact-local vs preact-main
  • many_updates: unsure 🔍 -3% - +2% (-0.58ms - +0.44ms)
    preact-local vs preact-main
  • text_update: unsure 🔍 -10% - +1% (-0.45ms - +0.05ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -3% - +1% (-1.46ms - +0.51ms)
    preact-local vs preact-main

usedJSHeapSize

  • 02_replace1k: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • 03_update10th1k_x16: unsure 🔍 -0% - +0% (-0.00ms - +0.01ms)
    preact-local vs preact-main
  • 07_create10k: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • filter_list: unsure 🔍 -1% - +0% (-0.01ms - +0.01ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -0% - +0% (-0.02ms - +0.00ms)
    preact-local vs preact-main
  • many_updates: unsure 🔍 -1% - +0% (-0.03ms - +0.02ms)
    preact-local vs preact-main
  • text_update: unsure 🔍 -2% - +4% (-0.01ms - +0.03ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main

Results

02_replace1k

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main125.33ms - 126.76ms-unsure 🔍
-1% - +1%
-0.86ms - +1.40ms
unsure 🔍
-1% - +1%
-1.32ms - +1.30ms
preact-local124.91ms - 126.64msunsure 🔍
-1% - +1%
-1.40ms - +0.86ms
-unsure 🔍
-1% - +1%
-1.68ms - +1.11ms
preact-hooks124.96ms - 127.15msunsure 🔍
-1% - +1%
-1.30ms - +1.32ms
unsure 🔍
-1% - +1%
-1.11ms - +1.68ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main3.27ms - 3.27ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
faster ✔
1% - 1%
0.02ms - 0.02ms
preact-local3.27ms - 3.27msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-faster ✔
1% - 1%
0.02ms - 0.02ms
preact-hooks3.29ms - 3.30msslower ❌
1% - 1%
0.02ms - 0.02ms
slower ❌
1% - 1%
0.02ms - 0.02ms
-

run-warmup-0

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main48.59ms - 50.65ms-unsure 🔍
-2% - +4%
-1.21ms - +1.92ms
unsure 🔍
-6% - +1%
-2.97ms - +0.63ms
preact-local48.09ms - 50.44msunsure 🔍
-4% - +2%
-1.92ms - +1.21ms
-unsure 🔍
-7% - +1%
-3.42ms - +0.37ms
preact-hooks49.31ms - 52.27msunsure 🔍
-1% - +6%
-0.63ms - +2.97ms
unsure 🔍
-1% - +7%
-0.37ms - +3.42ms
-

run-warmup-1

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main59.71ms - 62.37ms-unsure 🔍
-3% - +3%
-1.78ms - +2.05ms
unsure 🔍
-5% - +1%
-2.84ms - +0.75ms
preact-local59.52ms - 62.28msunsure 🔍
-3% - +3%
-2.05ms - +1.78ms
-unsure 🔍
-5% - +1%
-3.01ms - +0.65ms
preact-hooks60.88ms - 63.29msunsure 🔍
-1% - +5%
-0.75ms - +2.84ms
unsure 🔍
-1% - +5%
-0.65ms - +3.01ms
-

run-warmup-2

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main45.76ms - 47.57ms-unsure 🔍
-2% - +2%
-1.15ms - +1.11ms
unsure 🔍
-3% - +2%
-1.41ms - +0.99ms
preact-local46.01ms - 47.36msunsure 🔍
-2% - +2%
-1.11ms - +1.15ms
-unsure 🔍
-3% - +2%
-1.22ms - +0.85ms
preact-hooks46.09ms - 47.66msunsure 🔍
-2% - +3%
-0.99ms - +1.41ms
unsure 🔍
-2% - +3%
-0.85ms - +1.22ms
-

run-warmup-3

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main40.16ms - 40.89ms-unsure 🔍
-0% - +2%
-0.20ms - +0.86ms
unsure 🔍
-1% - +1%
-0.56ms - +0.48ms
preact-local39.82ms - 40.58msunsure 🔍
-2% - +0%
-0.86ms - +0.20ms
-unsure 🔍
-2% - +0%
-0.90ms - +0.16ms
preact-hooks40.20ms - 40.94msunsure 🔍
-1% - +1%
-0.48ms - +0.56ms
unsure 🔍
-0% - +2%
-0.16ms - +0.90ms
-

run-warmup-4

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main48.75ms - 50.26ms-unsure 🔍
-2% - +2%
-0.98ms - +1.12ms
unsure 🔍
-1% - +3%
-0.62ms - +1.32ms
preact-local48.71ms - 50.16msunsure 🔍
-2% - +2%
-1.12ms - +0.98ms
-unsure 🔍
-1% - +3%
-0.67ms - +1.23ms
preact-hooks48.54ms - 49.77msunsure 🔍
-3% - +1%
-1.32ms - +0.62ms
unsure 🔍
-2% - +1%
-1.23ms - +0.67ms
-

run-final

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main34.67ms - 35.36ms-unsure 🔍
-1% - +2%
-0.34ms - +0.67ms
unsure 🔍
-3% - +1%
-0.96ms - +0.28ms
preact-local34.48ms - 35.21msunsure 🔍
-2% - +1%
-0.67ms - +0.34ms
-unsure 🔍
-3% - +0%
-1.13ms - +0.13ms
preact-hooks34.83ms - 35.86msunsure 🔍
-1% - +3%
-0.28ms - +0.96ms
unsure 🔍
-0% - +3%
-0.13ms - +1.13ms
-
03_update10th1k_x16

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main33.58ms - 35.37ms-unsure 🔍
-4% - +3%
-1.50ms - +0.90ms
unsure 🔍
-2% - +6%
-0.53ms - +1.88ms
preact-local33.97ms - 35.57msunsure 🔍
-3% - +4%
-0.90ms - +1.50ms
-unsure 🔍
-1% - +6%
-0.17ms - +2.11ms
preact-hooks32.99ms - 34.61msunsure 🔍
-5% - +2%
-1.88ms - +0.53ms
unsure 🔍
-6% - +0%
-2.11ms - +0.17ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main3.23ms - 3.24ms-unsure 🔍
-0% - +0%
-0.01ms - +0.00ms
faster ✔
0% - 1%
0.01ms - 0.02ms
preact-local3.23ms - 3.24msunsure 🔍
-0% - +0%
-0.00ms - +0.01ms
-faster ✔
0% - 1%
0.01ms - 0.02ms
preact-hooks3.25ms - 3.26msslower ❌
0% - 1%
0.01ms - 0.02ms
slower ❌
0% - 1%
0.01ms - 0.02ms
-
07_create10k

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main1167.33ms - 1193.69ms-unsure 🔍
-1% - +2%
-14.49ms - +20.54ms
unsure 🔍
-1% - +1%
-15.23ms - +17.49ms
preact-local1165.95ms - 1189.02msunsure 🔍
-2% - +1%
-20.54ms - +14.49ms
-unsure 🔍
-1% - +1%
-16.96ms - +13.17ms
preact-hooks1169.69ms - 1189.07msunsure 🔍
-1% - +1%
-17.49ms - +15.23ms
unsure 🔍
-1% - +1%
-13.17ms - +16.96ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main25.87ms - 25.88ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
unsure 🔍
-0% - -0%
-0.02ms - -0.02ms
preact-local25.88ms - 25.88msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-unsure 🔍
-0% - -0%
-0.02ms - -0.02ms
preact-hooks25.89ms - 25.90msunsure 🔍
+0% - +0%
+0.02ms - +0.02ms
unsure 🔍
+0% - +0%
+0.02ms - +0.02ms
-
filter_list

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main21.10ms - 21.34ms-unsure 🔍
-0% - +1%
-0.05ms - +0.26ms
unsure 🔍
-1% - +1%
-0.23ms - +0.13ms
preact-local21.01ms - 21.21msunsure 🔍
-1% - +0%
-0.26ms - +0.05ms
-unsure 🔍
-1% - +0%
-0.32ms - +0.01ms
preact-hooks21.13ms - 21.40msunsure 🔍
-1% - +1%
-0.13ms - +0.23ms
unsure 🔍
-0% - +2%
-0.01ms - +0.32ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main1.31ms - 1.33ms-unsure 🔍
-0% - +1%
-0.01ms - +0.01ms
faster ✔
1% - 2%
0.01ms - 0.03ms
preact-local1.31ms - 1.32msunsure 🔍
-1% - +0%
-0.01ms - +0.01ms
-faster ✔
1% - 2%
0.02ms - 0.03ms
preact-hooks1.33ms - 1.34msslower ❌
1% - 2%
0.01ms - 0.03ms
slower ❌
1% - 2%
0.02ms - 0.03ms
-
hydrate1k

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main190.51ms - 195.36ms-unsure 🔍
-4% - +0%
-7.04ms - +0.59ms
unsure 🔍
-3% - +1%
-5.10ms - +1.34ms
preact-local193.22ms - 199.11msunsure 🔍
-0% - +4%
-0.59ms - +7.04ms
-unsure 🔍
-1% - +3%
-2.28ms - +4.97ms
preact-hooks192.70ms - 196.94msunsure 🔍
-1% - +3%
-1.34ms - +5.10ms
unsure 🔍
-3% - +1%
-4.97ms - +2.28ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main6.02ms - 6.04ms-unsure 🔍
-0% - +0%
-0.00ms - +0.02ms
faster ✔
0% - 1%
0.01ms - 0.03ms
preact-local6.01ms - 6.03msunsure 🔍
-0% - +0%
-0.02ms - +0.00ms
-faster ✔
0% - 1%
0.02ms - 0.04ms
preact-hooks6.04ms - 6.06msslower ❌
0% - 1%
0.01ms - 0.03ms
slower ❌
0% - 1%
0.02ms - 0.04ms
-
many_updates

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main20.66ms - 21.22ms-unsure 🔍
-2% - +3%
-0.44ms - +0.58ms
unsure 🔍
-3% - +1%
-0.53ms - +0.21ms
preact-local20.45ms - 21.30msunsure 🔍
-3% - +2%
-0.58ms - +0.44ms
-unsure 🔍
-3% - +1%
-0.72ms - +0.26ms
preact-hooks20.86ms - 21.35msunsure 🔍
-1% - +3%
-0.21ms - +0.53ms
unsure 🔍
-1% - +3%
-0.26ms - +0.72ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main4.39ms - 4.42ms-unsure 🔍
-0% - +1%
-0.02ms - +0.03ms
unsure 🔍
-1% - +0%
-0.02ms - +0.02ms
preact-local4.39ms - 4.42msunsure 🔍
-1% - +0%
-0.03ms - +0.02ms
-unsure 🔍
-1% - +0%
-0.03ms - +0.02ms
preact-hooks4.40ms - 4.43msunsure 🔍
-0% - +1%
-0.02ms - +0.02ms
unsure 🔍
-0% - +1%
-0.02ms - +0.03ms
-
text_update

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main4.11ms - 4.48ms-unsure 🔍
-1% - +11%
-0.05ms - +0.45ms
unsure 🔍
-9% - +3%
-0.39ms - +0.14ms
preact-local3.93ms - 4.27msunsure 🔍
-10% - +1%
-0.45ms - +0.05ms
-faster ✔
2% - 13%
0.07ms - 0.58ms
preact-hooks4.24ms - 4.61msunsure 🔍
-3% - +9%
-0.14ms - +0.39ms
slower ❌
2% - 14%
0.07ms - 0.58ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main0.62ms - 0.65ms-unsure 🔍
-4% - +2%
-0.03ms - +0.01ms
faster ✔
1% - 7%
0.01ms - 0.04ms
preact-local0.63ms - 0.66msunsure 🔍
-2% - +4%
-0.01ms - +0.03ms
-faster ✔
0% - 5%
0.00ms - 0.04ms
preact-hooks0.65ms - 0.68msslower ❌
1% - 7%
0.01ms - 0.04ms
unsure 🔍
-0% - +6%
+0.00ms - +0.04ms
-
todo

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main47.75ms - 49.35ms-unsure 🔍
-1% - +3%
-0.51ms - +1.46ms
unsure 🔍
-4% - +1%
-1.86ms - +0.26ms
preact-local47.51ms - 48.65msunsure 🔍
-3% - +1%
-1.46ms - +0.51ms
-faster ✔
1% - 4%
0.38ms - 2.17ms
preact-hooks48.67ms - 50.04msunsure 🔍
-1% - +4%
-0.26ms - +1.86ms
slower ❌
1% - 5%
0.38ms - 2.17ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main0.78ms - 0.78ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
faster ✔
3% - 3%
0.02ms - 0.03ms
preact-local0.78ms - 0.78msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-faster ✔
3% - 3%
0.02ms - 0.03ms
preact-hooks0.80ms - 0.80msslower ❌
3% - 4%
0.02ms - 0.03ms
slower ❌
3% - 4%
0.02ms - 0.03ms
-

tachometer-reporter-action v2 for Benchmarks

@coveralls
Copy link

Coverage Status

coverage: 99.283% (+0.001%) from 99.282% when pulling e4a73f8 on clear-nextDom into e24fdad on main.

@coveralls
Copy link

coveralls commented Oct 24, 2023

Coverage Status

coverage: 99.283% (+0.001%) from 99.282% when pulling 7d03e4b on clear-nextDom into e24fdad on main.

@github-actions
Copy link

github-actions bot commented Oct 24, 2023

Size Change: -10 B (0%)

Total Size: 57.2 kB

Filename Size Change
compat/dist/compat.js 3.95 kB -2 B (0%)
compat/dist/compat.module.js 3.87 kB -3 B (0%)
compat/dist/compat.umd.js 4.01 kB -4 B (0%)
dist/preact.min.js 4.45 kB -4 B (0%)
dist/preact.min.module.js 4.45 kB -1 B
dist/preact.module.js 4.45 kB +3 B (0%)
dist/preact.umd.js 4.49 kB +1 B
ℹ️ View Unchanged
Filename Size Change
debug/dist/debug.js 3.5 kB 0 B
debug/dist/debug.module.js 3.5 kB 0 B
debug/dist/debug.umd.js 3.58 kB 0 B
devtools/dist/devtools.js 231 B 0 B
devtools/dist/devtools.module.js 240 B 0 B
devtools/dist/devtools.umd.js 315 B 0 B
dist/preact.js 4.42 kB 0 B
dist/preact.min.umd.js 4.48 kB 0 B
hooks/dist/hooks.js 1.53 kB 0 B
hooks/dist/hooks.module.js 1.56 kB 0 B
hooks/dist/hooks.umd.js 1.62 kB 0 B
jsx-runtime/dist/jsxRuntime.js 360 B 0 B
jsx-runtime/dist/jsxRuntime.module.js 326 B 0 B
jsx-runtime/dist/jsxRuntime.umd.js 441 B 0 B
test-utils/dist/testUtils.js 453 B 0 B
test-utils/dist/testUtils.module.js 454 B 0 B
test-utils/dist/testUtils.umd.js 536 B 0 B

compressed-size-action

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

Nice find, the many updates perf is weird though

@andrewiggins
Copy link
Member Author

Yea, agreed. Looking into it. Given how large of a range it is, I wonder if we are catching a new GC in the measured duration with this update

Locally improves perf??
@andrewiggins
Copy link
Member Author

Wow. The fact that 7d03e4b fixed the many_updates regression is utterly baffling to me

@andrewiggins andrewiggins merged commit e6edf13 into main Oct 24, 2023
13 checks passed
@andrewiggins andrewiggins deleted the clear-nextDom branch October 24, 2023 18:49
@JoviDeCroock JoviDeCroock mentioned this pull request Nov 3, 2023
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.

None yet

3 participants