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

Comment denoted hydration #4636

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

Conversation

JoviDeCroock
Copy link
Member

Relates to #4442
Implementation from preactjs/preact-render-to-string#376
Supersedes #4444

This implements a hydration approach with the comment markers, one thing that's noteworthy is that oldDom in our diffChildren algorithm becomes stale.

We diff the wrapping element of the Suspense and non-suspenseful child, we get to an oldDom which is the first child-node of said series. When we suspend we don't move oldDom, we can try and move it inside of diff but this won't affect the continued diffChildren so we are stuck inserting that node in front of our oldDom.

This has been solved in 647d138 through correctly skipping comment nodes while placing children.

I think the last part of this research would be to set up a comprehensive test suite for both renderToStringAsync as well as renderToStream so we can have fixtures for this behaviour, what do you all think?

Copy link

github-actions bot commented Jan 18, 2025

📊 Tachometer Benchmark Results

Summary

duration

  • create10k: unsure 🔍 -0% - +1% (-2.88ms - +5.62ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -1% - +0% (-0.16ms - +0.04ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -0% - +2% (-0.15ms - +1.17ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -1% - +3% (-0.17ms - +0.64ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -1% - +1% (-0.55ms - +0.75ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -4% - +5% (-0.08ms - +0.10ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -1% - +0% (-0.19ms - +0.15ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 -4% - +4% (-1.20ms - +1.16ms)
    preact-local vs preact-main

usedJSHeapSize

  • create10k: unsure 🔍 +0% - +0% (+0.01ms - +0.01ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -0% - +2% (-0.00ms - +0.04ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -3% - +4% (-0.31ms - +0.39ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -0% - +1% (-0.01ms - +0.03ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -0% - +1% (-0.01ms - +0.02ms)
    preact-local vs preact-main
  • text-update: slower ❌ 1% - 1% (0.01ms - 0.01ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -0% - +2% (-0.00ms - +0.02ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 +0% - +0% (+0.00ms - +0.01ms)
    preact-local vs preact-main

Results

create10k

duration

VersionAvg timevs preact-localvs preact-main
preact-local945.00ms - 952.34ms-unsure 🔍
-0% - +1%
-2.88ms - +5.62ms
preact-main945.17ms - 949.44msunsure 🔍
-1% - +0%
-5.62ms - +2.88ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local19.21ms - 19.21ms-unsure 🔍
+0% - +0%
+0.01ms - +0.01ms
preact-main19.20ms - 19.20msunsure 🔍
-0% - -0%
-0.01ms - -0.01ms
-
filter-list

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.57ms - 16.65ms-unsure 🔍
-1% - +0%
-0.16ms - +0.04ms
preact-main16.57ms - 16.77msunsure 🔍
-0% - +1%
-0.04ms - +0.16ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.53ms - 1.56ms-unsure 🔍
-0% - +2%
-0.00ms - +0.04ms
preact-main1.52ms - 1.54msunsure 🔍
-2% - +0%
-0.04ms - +0.00ms
-
hydrate1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local72.79ms - 73.83ms-unsure 🔍
-0% - +2%
-0.15ms - +1.17ms
preact-main72.39ms - 73.21msunsure 🔍
-2% - +0%
-1.17ms - +0.15ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local10.23ms - 10.74ms-unsure 🔍
-3% - +4%
-0.31ms - +0.39ms
preact-main10.21ms - 10.68msunsure 🔍
-4% - +3%
-0.39ms - +0.31ms
-
many-updates

duration

VersionAvg timevs preact-localvs preact-main
preact-local18.44ms - 19.08ms-unsure 🔍
-1% - +3%
-0.17ms - +0.64ms
preact-main18.28ms - 18.78msunsure 🔍
-3% - +1%
-0.64ms - +0.17ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.77ms - 3.80ms-unsure 🔍
-0% - +1%
-0.01ms - +0.03ms
preact-main3.76ms - 3.79msunsure 🔍
-1% - +0%
-0.03ms - +0.01ms
-
replace1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local71.12ms - 71.96ms-unsure 🔍
-1% - +1%
-0.55ms - +0.75ms
preact-main70.95ms - 71.93msunsure 🔍
-1% - +1%
-0.75ms - +0.55ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local2.97ms - 2.99ms-unsure 🔍
-0% - +1%
-0.01ms - +0.02ms
preact-main2.97ms - 2.99msunsure 🔍
-1% - +0%
-0.02ms - +0.01ms
-

run-warmup-0

VersionAvg timevs preact-localvs preact-main
preact-local31.33ms - 31.89ms-unsure 🔍
-1% - +2%
-0.21ms - +0.60ms
preact-main31.12ms - 31.70msunsure 🔍
-2% - +1%
-0.60ms - +0.21ms
-

run-warmup-1

VersionAvg timevs preact-localvs preact-main
preact-local36.36ms - 37.61ms-unsure 🔍
-3% - +2%
-1.10ms - +0.70ms
preact-main36.54ms - 37.83msunsure 🔍
-2% - +3%
-0.70ms - +1.10ms
-

run-warmup-2

VersionAvg timevs preact-localvs preact-main
preact-local27.29ms - 27.72ms-unsure 🔍
-2% - +1%
-0.43ms - +0.21ms
preact-main27.38ms - 27.86msunsure 🔍
-1% - +2%
-0.21ms - +0.43ms
-

run-warmup-3

VersionAvg timevs preact-localvs preact-main
preact-local27.35ms - 28.79ms-unsure 🔍
-6% - +1%
-1.74ms - +0.32ms
preact-main28.04ms - 29.52msunsure 🔍
-1% - +6%
-0.32ms - +1.74ms
-

run-warmup-4

VersionAvg timevs preact-localvs preact-main
preact-local25.05ms - 26.37ms-unsure 🔍
-5% - +2%
-1.42ms - +0.44ms
preact-main25.55ms - 26.85msunsure 🔍
-2% - +6%
-0.44ms - +1.42ms
-

run-final

VersionAvg timevs preact-localvs preact-main
preact-local23.09ms - 23.53ms-unsure 🔍
-1% - +1%
-0.34ms - +0.31ms
preact-main23.09ms - 23.57msunsure 🔍
-1% - +1%
-0.31ms - +0.34ms
-
text-update

duration

VersionAvg timevs preact-localvs preact-main
preact-local1.95ms - 2.08ms-unsure 🔍
-4% - +5%
-0.08ms - +0.10ms
preact-main1.94ms - 2.07msunsure 🔍
-5% - +4%
-0.10ms - +0.08ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.12ms - 1.12ms-slower ❌
1% - 1%
0.01ms - 0.01ms
preact-main1.11ms - 1.11msfaster ✔
1% - 1%
0.01ms - 0.01ms
-
todo

duration

VersionAvg timevs preact-localvs preact-main
preact-local34.10ms - 34.33ms-unsure 🔍
-1% - +0%
-0.19ms - +0.15ms
preact-main34.11ms - 34.36msunsure 🔍
-0% - +1%
-0.15ms - +0.19ms
-

usedJSHeapSize

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

duration

VersionAvg timevs preact-localvs preact-main
preact-local31.74ms - 33.56ms-unsure 🔍
-4% - +4%
-1.20ms - +1.16ms
preact-main31.93ms - 33.42msunsure 🔍
-4% - +4%
-1.16ms - +1.20ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local2.92ms - 2.93ms-unsure 🔍
+0% - +0%
+0.00ms - +0.01ms
preact-main2.91ms - 2.92msunsure 🔍
-0% - -0%
-0.01ms - -0.00ms
-

tachometer-reporter-action v2 for CI

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/diff/children.js:133

  • [nitpick] The variable name 'toResolve' is ambiguous. It should be renamed to something more descriptive like 'commentMarkersToResolve'.
let toResolve = 0;

src/diff/children.js:134

  • Ensure that the new logic for handling comment nodes is covered by tests.
while ((oldDom && oldDom.nodeType == 8) || toResolve > 0) {
Copy link

github-actions bot commented Jan 18, 2025

Size Change: +785 B (+1.26%)

Total Size: 63.1 kB

Filename Size Change
dist/preact.js 4.83 kB +132 B (+2.81%)
dist/preact.min.js 4.85 kB +132 B (+2.8%)
dist/preact.min.module.js 4.85 kB +130 B (+2.75%)
dist/preact.min.umd.js 4.87 kB +130 B (+2.74%)
dist/preact.module.js 4.84 kB +129 B (+2.74%)
dist/preact.umd.js 4.89 kB +132 B (+2.78%)
ℹ️ View Unchanged
Filename Size
compat/dist/compat.js 4.12 kB
compat/dist/compat.module.js 4.05 kB
compat/dist/compat.umd.js 4.19 kB
debug/dist/debug.js 3.83 kB
debug/dist/debug.module.js 3.83 kB
debug/dist/debug.umd.js 3.91 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.54 kB
hooks/dist/hooks.module.js 1.57 kB
hooks/dist/hooks.umd.js 1.61 kB
jsx-runtime/dist/jsxRuntime.js 978 B
jsx-runtime/dist/jsxRuntime.module.js 952 B
jsx-runtime/dist/jsxRuntime.umd.js 1.05 kB
test-utils/dist/testUtils.js 473 B
test-utils/dist/testUtils.module.js 477 B
test-utils/dist/testUtils.umd.js 555 B

compressed-size-action

@coveralls
Copy link

coveralls commented Jan 18, 2025

Coverage Status

coverage: 99.618% (+0.001%) from 99.617%
when pulling 4988f25 on comment-denoted-hydration
into 28a937c on main.

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.

Sorry this took so long, wanted to find time to go back through your RFC & the RTS pull as my memory had become rusty. Looks great!

Re:comprehensive test suite, certainly would be a big benefit though I imagine it'd be a fair bit of work to cover all the various situations. Wonder how comprehensive React's suite is, might be able to repurpose some tests with less effort than writing from scratch.

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