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

Single text node hot path #4523

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Single text node hot path #4523

wants to merge 7 commits into from

Conversation

JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Oct 3, 2024

Supersedes #3939

Similar to 3939 we are seeing some operations take longer as rather than mutating the text-node we'll be swapping positions instead. The impact seems higher in skew based diff though so not sure whether the performance impact will be as high as in 3939.

The replace_1k difference is similar to #3939 (comment)

This could also be problematic with signals as text-updates won't automatically update afaik

Looks like this should not break signals actually
image

From #2618 we can derive that there are actually a lot of cases where the single child type is a text-node.

Copy link

github-actions bot commented Oct 3, 2024

📊 Tachometer Benchmark Results

Summary

duration

  • create10k: faster ✔ 0% - 1% (1.14ms - 13.02ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -0% - +1% (-0.05ms - +0.10ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -4% - +0% (-3.31ms - +0.25ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -3% - +1% (-0.44ms - +0.12ms)
    preact-local vs preact-main
  • replace1k: slower ❌ 6% - 10% (4.43ms - 7.14ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -2% - +5% (-0.03ms - +0.10ms)
    preact-local vs preact-main
  • todo: faster ✔ 5% - 8% (1.77ms - 2.70ms)
    preact-local vs preact-main
  • update10th1k: faster ✔ 2% - 7% (0.76ms - 2.36ms)
    preact-local vs preact-main

usedJSHeapSize

  • create10k: faster ✔ 7% - 7% (1.75ms - 1.78ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -1% - +1% (-0.01ms - +0.02ms)
    preact-local vs preact-main
  • hydrate1k: faster ✔ 5% - 8% (0.82ms - 1.23ms)
    preact-local vs preact-main
  • many-updates: faster ✔ 34% - 35% (1.58ms - 1.61ms)
    preact-local vs preact-main
  • replace1k: faster ✔ 3% - 5% (0.11ms - 0.16ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 +0% - +0% (+0.00ms - +0.00ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -1% - +1% (-0.01ms - +0.02ms)
    preact-local vs preact-main
  • update10th1k: faster ✔ 4% - 5% (0.15ms - 0.17ms)
    preact-local vs preact-main

Results

create10k

duration

VersionAvg timevs preact-localvs preact-main
preact-local957.55ms - 964.40ms-faster ✔
0% - 1%
1.14ms - 13.02ms
preact-main963.20ms - 972.90msslower ❌
0% - 1%
1.14ms - 13.02ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local23.61ms - 23.63ms-faster ✔
7% - 7%
1.75ms - 1.78ms
preact-main25.37ms - 25.40msslower ❌
7% - 8%
1.75ms - 1.78ms
-
filter-list

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.54ms - 16.68ms-unsure 🔍
-0% - +1%
-0.05ms - +0.10ms
preact-main16.55ms - 16.61msunsure 🔍
-1% - +0%
-0.10ms - +0.05ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.67ms - 1.70ms-unsure 🔍
-1% - +1%
-0.01ms - +0.02ms
preact-main1.66ms - 1.69msunsure 🔍
-1% - +1%
-0.02ms - +0.01ms
-
hydrate1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local74.93ms - 78.39ms-unsure 🔍
-4% - +0%
-3.31ms - +0.25ms
preact-main77.76ms - 78.63msunsure 🔍
-0% - +4%
-0.25ms - +3.31ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local14.45ms - 14.76ms-faster ✔
5% - 8%
0.82ms - 1.23ms
preact-main15.50ms - 15.77msslower ❌
6% - 9%
0.82ms - 1.23ms
-
many-updates

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.54ms - 16.59ms-unsure 🔍
-3% - +1%
-0.44ms - +0.12ms
preact-main16.45ms - 17.00msunsure 🔍
-1% - +3%
-0.12ms - +0.44ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local2.99ms - 3.01ms-faster ✔
34% - 35%
1.58ms - 1.61ms
preact-main4.58ms - 4.60msslower ❌
53% - 54%
1.58ms - 1.61ms
-
replace1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local78.91ms - 81.32ms-slower ❌
6% - 10%
4.43ms - 7.14ms
preact-main73.71ms - 74.95msfaster ✔
6% - 9%
4.43ms - 7.14ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.44ms - 3.50ms-faster ✔
3% - 5%
0.11ms - 0.16ms
preact-main3.60ms - 3.61msslower ❌
3% - 5%
0.11ms - 0.16ms
-

run-warmup-0

VersionAvg timevs preact-localvs preact-main
preact-local30.64ms - 31.81ms-unsure 🔍
-4% - +0%
-1.20ms - +0.15ms
preact-main31.42ms - 32.09msunsure 🔍
-0% - +4%
-0.15ms - +1.20ms
-

run-warmup-1

VersionAvg timevs preact-localvs preact-main
preact-local35.39ms - 36.50ms-faster ✔
3% - 8%
1.14ms - 3.07ms
preact-main37.26ms - 38.85msslower ❌
3% - 9%
1.14ms - 3.07ms
-

run-warmup-2

VersionAvg timevs preact-localvs preact-main
preact-local28.64ms - 29.21ms-slower ❌
6% - 9%
1.63ms - 2.30ms
preact-main26.78ms - 27.14msfaster ✔
6% - 8%
1.63ms - 2.30ms
-

run-warmup-3

VersionAvg timevs preact-localvs preact-main
preact-local32.31ms - 33.98ms-slower ❌
16% - 24%
4.39ms - 6.49ms
preact-main27.07ms - 28.35msfaster ✔
14% - 19%
4.39ms - 6.49ms
-

run-warmup-4

VersionAvg timevs preact-localvs preact-main
preact-local20.86ms - 21.27ms-faster ✔
2% - 6%
0.33ms - 1.22ms
preact-main21.45ms - 22.24msslower ❌
2% - 6%
0.33ms - 1.22ms
-

run-final

VersionAvg timevs preact-localvs preact-main
preact-local22.55ms - 23.36ms-unsure 🔍
-4% - +0%
-0.91ms - +0.06ms
preact-main23.10ms - 23.65msunsure 🔍
-0% - +4%
-0.06ms - +0.91ms
-
text-update

duration

VersionAvg timevs preact-localvs preact-main
preact-local1.96ms - 2.05ms-unsure 🔍
-2% - +5%
-0.03ms - +0.10ms
preact-main1.92ms - 2.02msunsure 🔍
-5% - +2%
-0.10ms - +0.03ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.12ms - 1.12ms-unsure 🔍
+0% - +0%
+0.00ms - +0.00ms
preact-main1.12ms - 1.12msunsure 🔍
-0% - -0%
-0.00ms - -0.00ms
-
todo

duration

VersionAvg timevs preact-localvs preact-main
preact-local31.82ms - 32.71ms-faster ✔
5% - 8%
1.77ms - 2.70ms
preact-main34.37ms - 34.63msslower ❌
5% - 8%
1.77ms - 2.70ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.23ms - 1.25ms-unsure 🔍
-1% - +1%
-0.01ms - +0.02ms
preact-main1.23ms - 1.25msunsure 🔍
-1% - +1%
-0.02ms - +0.01ms
-
update10th1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local32.56ms - 33.73ms-faster ✔
2% - 7%
0.76ms - 2.36ms
preact-main34.16ms - 35.24msslower ❌
2% - 7%
0.76ms - 2.36ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.38ms - 3.39ms-faster ✔
4% - 5%
0.15ms - 0.17ms
preact-main3.54ms - 3.55msslower ❌
4% - 5%
0.15ms - 0.17ms
-

tachometer-reporter-action v2 for Benchmarks

Copy link

github-actions bot commented Oct 3, 2024

Size Change: +420 B (+0.68%)

Total Size: 62.5 kB

Filename Size Change
dist/preact.js 4.74 kB +69 B (+1.48%)
dist/preact.min.js 4.76 kB +71 B (+1.51%)
dist/preact.min.module.js 4.76 kB +70 B (+1.49%)
dist/preact.min.umd.js 4.79 kB +71 B (+1.5%)
dist/preact.module.js 4.75 kB +71 B (+1.52%)
dist/preact.umd.js 4.8 kB +68 B (+1.44%)
ℹ️ View Unchanged
Filename Size
compat/dist/compat.js 4.13 kB
compat/dist/compat.module.js 4.05 kB
compat/dist/compat.umd.js 4.19 kB
debug/dist/debug.js 3.82 kB
debug/dist/debug.module.js 3.83 kB
debug/dist/debug.umd.js 3.9 kB
devtools/dist/devtools.js 260 B
devtools/dist/devtools.module.js 274 B
devtools/dist/devtools.umd.js 346 B
hooks/dist/hooks.js 1.53 kB
hooks/dist/hooks.module.js 1.56 kB
hooks/dist/hooks.umd.js 1.6 kB
jsx-runtime/dist/jsxRuntime.js 976 B
jsx-runtime/dist/jsxRuntime.module.js 949 B
jsx-runtime/dist/jsxRuntime.umd.js 1.05 kB
test-utils/dist/testUtils.js 451 B
test-utils/dist/testUtils.module.js 456 B
test-utils/dist/testUtils.umd.js 536 B

compressed-size-action

@JoviDeCroock JoviDeCroock changed the title Revive 3939 Single text node hot path Oct 3, 2024
@coveralls
Copy link

coveralls commented Oct 3, 2024

Coverage Status

coverage: 99.49% (+0.002%) from 99.488%
when pulling 3bf818a on revive-3939
into 8deab11 on main.

@JoviDeCroock JoviDeCroock deleted the revive-3939 branch October 9, 2024 13:06
@JoviDeCroock JoviDeCroock restored the revive-3939 branch October 12, 2024 07:07
@JoviDeCroock JoviDeCroock deleted the revive-3939 branch October 12, 2024 07:07
@JoviDeCroock JoviDeCroock restored the revive-3939 branch October 12, 2024 07:07
@JoviDeCroock JoviDeCroock reopened this Oct 12, 2024
@JoviDeCroock JoviDeCroock marked this pull request as ready for review October 12, 2024 07:08
@JoviDeCroock JoviDeCroock force-pushed the revive-3939 branch 2 times, most recently from 20e7020 to 91f6188 Compare October 12, 2024 07:21
Copy link
Member

@rschristian rschristian left a comment

Choose a reason for hiding this comment

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

Re:Andre's comment about the "regression" in replace1k, have you by chance tried giving it more warmup runs? Say bumping up to 25 like a few of the other benches?

That very well might have been in one of your force pushes, just thought I'd ask.

@rschristian
Copy link
Member

rschristian commented Oct 12, 2024

Looking at the results, the warmup might close the gap a little on average, but not totally: https://github.com/preactjs/preact/actions/runs/11304050028/job/31441949188

Can probably revert/drop that, sorry. Was good to confirm I suppose though.

@JoviDeCroock JoviDeCroock force-pushed the revive-3939 branch 4 times, most recently from e109c40 to c664014 Compare October 12, 2024 09:15
Copy link

github-actions bot commented Oct 13, 2024

📊 Tachometer Benchmark Results

Summary

duration

  • create10k: unsure 🔍 -1% - +1% (-8.86ms - +5.86ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -0% - +0% (-0.03ms - +0.04ms)
    preact-local vs preact-main
  • hydrate1k: faster ✔ 3% - 5% (1.95ms - 3.63ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -2% - +1% (-0.28ms - +0.15ms)
    preact-local vs preact-main
  • replace1k: faster ✔ 0% - 2% (0.34ms - 1.75ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -1% - +5% (-0.01ms - +0.10ms)
    preact-local vs preact-main
  • todo: faster ✔ 8% - 9% (2.64ms - 3.00ms)
    preact-local vs preact-main
  • update10th1k: faster ✔ 0% - 5% (0.03ms - 1.67ms)
    preact-local vs preact-main

usedJSHeapSize

  • create10k: faster ✔ 2% - 3% (0.60ms - 0.65ms)
    preact-local vs preact-main
  • filter-list: slower ❌ 0% - 2% (0.00ms - 0.03ms)
    preact-local vs preact-main
  • hydrate1k: faster ✔ 3% - 6% (0.45ms - 0.89ms)
    preact-local vs preact-main
  • many-updates: faster ✔ 31% - 31% (1.41ms - 1.43ms)
    preact-local vs preact-main
  • replace1k: faster ✔ 1% - 3% (0.05ms - 0.10ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 +0% - +0% (+0.00ms - +0.00ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -0% - +2% (-0.00ms - +0.02ms)
    preact-local vs preact-main
  • update10th1k: faster ✔ 3% - 4% (0.11ms - 0.13ms)
    preact-local vs preact-main

Results

create10k

duration

VersionAvg timevs preact-localvs preact-main
preact-local935.54ms - 943.25ms-unsure 🔍
-1% - +1%
-8.86ms - +5.86ms
preact-main934.63ms - 947.17msunsure 🔍
-1% - +1%
-5.86ms - +8.86ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local24.74ms - 24.78ms-faster ✔
2% - 3%
0.60ms - 0.65ms
preact-main25.37ms - 25.40msslower ❌
2% - 3%
0.60ms - 0.65ms
-
filter-list

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.55ms - 16.61ms-unsure 🔍
-0% - +0%
-0.03ms - +0.04ms
preact-main16.55ms - 16.60msunsure 🔍
-0% - +0%
-0.04ms - +0.03ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.67ms - 1.70ms-slower ❌
0% - 2%
0.00ms - 0.03ms
preact-main1.66ms - 1.68msfaster ✔
0% - 2%
0.00ms - 0.03ms
-
hydrate1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local72.64ms - 73.96ms-faster ✔
3% - 5%
1.95ms - 3.63ms
preact-main75.57ms - 76.60msslower ❌
3% - 5%
1.95ms - 3.63ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local14.86ms - 15.21ms-faster ✔
3% - 6%
0.45ms - 0.89ms
preact-main15.56ms - 15.84msslower ❌
3% - 6%
0.45ms - 0.89ms
-
many-updates

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.22ms - 16.58ms-unsure 🔍
-2% - +1%
-0.28ms - +0.15ms
preact-main16.35ms - 16.59msunsure 🔍
-1% - +2%
-0.15ms - +0.28ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.15ms - 3.17ms-faster ✔
31% - 31%
1.41ms - 1.43ms
preact-main4.58ms - 4.59msslower ❌
44% - 45%
1.41ms - 1.43ms
-
replace1k
  • Browser: chrome-headless
  • Sample size: 100
  • Built by: CI #3970
  • Commit: 3bf818a

duration

VersionAvg timevs preact-localvs preact-main
preact-local73.16ms - 73.58ms-faster ✔
0% - 2%
0.34ms - 1.75ms
preact-main73.75ms - 75.09msslower ❌
0% - 2%
0.34ms - 1.75ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.54ms - 3.56ms-faster ✔
1% - 3%
0.05ms - 0.10ms
preact-main3.60ms - 3.65msslower ❌
1% - 3%
0.05ms - 0.10ms
-

run-warmup-0

VersionAvg timevs preact-localvs preact-main
preact-local30.73ms - 31.29ms-unsure 🔍
-1% - +1%
-0.32ms - +0.40ms
preact-main30.75ms - 31.19msunsure 🔍
-1% - +1%
-0.40ms - +0.32ms
-

run-warmup-1

VersionAvg timevs preact-localvs preact-main
preact-local35.70ms - 36.70ms-unsure 🔍
-4% - +0%
-1.65ms - +0.03ms
preact-main36.34ms - 37.69msunsure 🔍
-0% - +5%
-0.03ms - +1.65ms
-

run-warmup-2

VersionAvg timevs preact-localvs preact-main
preact-local26.67ms - 27.00ms-unsure 🔍
-2% - +1%
-0.49ms - +0.18ms
preact-main26.70ms - 27.28msunsure 🔍
-1% - +2%
-0.18ms - +0.49ms
-

run-warmup-3

VersionAvg timevs preact-localvs preact-main
preact-local26.26ms - 26.97ms-faster ✔
0% - 5%
0.08ms - 1.39ms
preact-main26.80ms - 27.91msslower ❌
0% - 5%
0.08ms - 1.39ms
-

run-warmup-4

VersionAvg timevs preact-localvs preact-main
preact-local21.35ms - 21.96ms-unsure 🔍
-1% - +2%
-0.31ms - +0.54ms
preact-main21.25ms - 21.84msunsure 🔍
-2% - +1%
-0.54ms - +0.31ms
-

run-final

VersionAvg timevs preact-localvs preact-main
preact-local23.01ms - 23.31ms-unsure 🔍
-0% - +2%
-0.04ms - +0.41ms
preact-main22.82ms - 23.15msunsure 🔍
-2% - +0%
-0.41ms - +0.04ms
-
text-update
  • Browser: chrome-headless
  • Sample size: 230
  • Built by: CI #3970
  • Commit: 3bf818a

duration

VersionAvg timevs preact-localvs preact-main
preact-local1.95ms - 2.04ms-unsure 🔍
-1% - +5%
-0.01ms - +0.10ms
preact-main1.92ms - 1.99msunsure 🔍
-5% - +1%
-0.10ms - +0.01ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.12ms - 1.12ms-unsure 🔍
+0% - +0%
+0.00ms - +0.00ms
preact-main1.12ms - 1.12msunsure 🔍
-0% - -0%
-0.00ms - -0.00ms
-
todo

duration

VersionAvg timevs preact-localvs preact-main
preact-local31.85ms - 32.10ms-faster ✔
8% - 9%
2.64ms - 3.00ms
preact-main34.66ms - 34.93msslower ❌
8% - 9%
2.64ms - 3.00ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.24ms - 1.26ms-unsure 🔍
-0% - +2%
-0.00ms - +0.02ms
preact-main1.23ms - 1.25msunsure 🔍
-2% - +0%
-0.02ms - +0.00ms
-
update10th1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local33.04ms - 34.35ms-faster ✔
0% - 5%
0.03ms - 1.67ms
preact-main34.06ms - 35.03msslower ❌
0% - 5%
0.03ms - 1.67ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.41ms - 3.43ms-faster ✔
3% - 4%
0.11ms - 0.13ms
preact-main3.53ms - 3.54msslower ❌
3% - 4%
0.11ms - 0.13ms
-

tachometer-reporter-action v2 for CI

@JoviDeCroock JoviDeCroock force-pushed the revive-3939 branch 2 times, most recently from 20942aa to 021c18d Compare October 13, 2024 10:30
Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

Very impressed with the findings. Really good work!


newVNode._children = [
// @ts-expect-error
createVNode(null, (dom.textContent = newChildren), null, null)
Copy link
Member

Choose a reason for hiding this comment

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

We might want to consider using dom.appendChild(document.createTextNode(newChildren)) and manually removing previous children. Otherwise, rendering a single text child will blow away non-preact-rendered children from a parent element.

Comment on lines +501 to +516
} else if (typeof newChildren === 'string') {
if (newChildren !== oldProps.children) {
while (oldVNode._children && (i = oldVNode._children.pop())) {
// Setting textContent on the dom element will unmount all DOM nodes
// of the previous children, so we don't need to remove DOM in this
// call to unmount
unmount(i, oldVNode, true);
}

newVNode._children = [
// @ts-expect-error
createVNode(null, (dom.textContent = newChildren), null, null)
];
// @ts-expect-error
newVNode._children[0]._dom = dom.firstChild;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} else if (typeof newChildren === 'string') {
if (newChildren !== oldProps.children) {
while (oldVNode._children && (i = oldVNode._children.pop())) {
// Setting textContent on the dom element will unmount all DOM nodes
// of the previous children, so we don't need to remove DOM in this
// call to unmount
unmount(i, oldVNode, true);
}
newVNode._children = [
// @ts-expect-error
createVNode(null, (dom.textContent = newChildren), null, null)
];
// @ts-expect-error
newVNode._children[0]._dom = dom.firstChild;
}
} else if (typeof newChildren === 'string' && typeof oldProps.children === 'string') {
if (newChildren !== oldProps.children) {
oldVNode._children[0]._dom.data = newChildren;
newVNode._children = oldVNode._children;
oldVNode._children = [];
}

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.

6 participants