Skip to content

add set_if_changed(Attributes) and hydrate(trait Apply) methods#4158

Open
tikitko wants to merge 2 commits into
yewstack:masterfrom
tikitko:img-src-re-downloaded-on-hydration-because-all-attributes-are-unconditionally-re-applied
Open

add set_if_changed(Attributes) and hydrate(trait Apply) methods#4158
tikitko wants to merge 2 commits into
yewstack:masterfrom
tikitko:img-src-re-downloaded-on-hydration-because-all-attributes-are-unconditionally-re-applied

Conversation

@tikitko
Copy link
Copy Markdown
Contributor

@tikitko tikitko commented May 16, 2026

Description

Introduce an optimized hydration path for DOM attributes - skip unnecessary set_attribute calls when SSR has already written the correct value.

Fixes #4157

Checklist

  • I have reviewed my own code
  • I have added tests

@tikitko tikitko changed the title feat(hydration): add set_if_changed(Attributes) and hydrate(trait Apply) methods add set_if_changed(Attributes) and hydrate(trait Apply) methods May 16, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 16, 2026

Benchmark - core

Yew Master

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.458 ns      │ 2.845 ns      │ 2.462 ns      │ 2.489 ns      │ 100     │ 1000000000

Pull Request

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.459 ns      │ 2.494 ns      │ 2.463 ns      │ 2.465 ns      │ 100     │ 1000000000

@tikitko tikitko marked this pull request as draft May 16, 2026 12:52
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 16, 2026

Size Comparison

Details
examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 100.049 100.049 0 0.000%
boids 163.705 163.705 0 0.000%
communication_child_to_parent 93.456 93.456 0 0.000%
communication_grandchild_with_grandparent 105.574 105.574 0 0.000%
communication_grandparent_to_grandchild 101.890 101.890 0 0.000%
communication_parent_to_child 90.856 90.856 0 0.000%
contexts 105.854 105.854 0 0.000%
counter 85.740 85.740 0 0.000%
counter_functional 87.855 87.855 0 0.000%
dyn_create_destroy_apps 89.626 89.626 0 0.000%
file_upload 98.807 98.807 0 0.000%
function_delayed_input 94.439 94.439 0 0.000%
function_memory_game 167.365 167.365 0 0.000%
function_router 398.679 398.679 0 0.000%
function_todomvc 164.174 164.174 0 0.000%
futures 234.879 234.879 0 0.000%
game_of_life 100.396 100.396 0 0.000%
immutable 257.884 257.884 0 0.000%
inner_html 80.593 80.593 0 0.000%
js_callback 109.631 109.631 0 0.000%
keyed_list 175.731 175.731 0 0.000%
mount_point 83.949 83.949 0 0.000%
nested_list 112.602 112.602 0 0.000%
node_refs 91.449 91.449 0 0.000%
password_strength 1719.715 1719.715 0 0.000%
portals 93.081 93.081 0 0.000%
router 364.858 364.858 0 0.000%
suspense 113.553 113.553 0 0.000%
timer 88.258 88.258 0 0.000%
timer_functional 99.197 99.197 0 0.000%
todomvc 141.060 141.060 0 0.000%
two_apps 85.921 85.921 0 0.000%
web_worker_fib 136.158 136.158 0 0.000%
web_worker_prime 184.604 184.604 0 0.000%
webgl 82.738 82.738 0 0.000%

✅ None of the examples has changed their size significantly.

@github-actions
Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 7fe55ee):

https://yew-rs-api--pr4158-img-src-re-downloade-7cvcwxmv.web.app

(expires Sat, 23 May 2026 12:58:22 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 16, 2026

Benchmark - SSR

Yew Master

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 291.449 293.654 291.786 0.667
Hello World 10 462.535 485.600 468.498 8.910
Function Router 10 31305.011 31815.069 31578.255 148.592
Concurrent Task 10 1005.993 1007.307 1006.681 0.438
Many Providers 10 999.761 1048.136 1011.873 16.259

Pull Request

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 291.363 295.034 291.828 1.129
Hello World 10 474.704 497.274 484.033 7.154
Function Router 10 31607.399 32184.770 31840.534 173.487
Concurrent Task 10 1005.484 1008.879 1006.966 0.890
Many Providers 10 1032.042 1077.991 1042.607 13.399

@tikitko
Copy link
Copy Markdown
Contributor Author

tikitko commented May 16, 2026

I checked Leptos - they skip setting attributes entirely on hydrate.
What do you think, guys?

@tikitko tikitko marked this pull request as ready for review May 16, 2026 13:13
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.

<img src> re-downloaded on hydration because all attributes are unconditionally re-applied

1 participant