Skip to content

perf: cache empty VList Rc in VNode::default to avoid repeated heap allocation#4089

Draft
Madoshakalaka wants to merge 1 commit intomasterfrom
perf/vnode-default-avoid-allocation
Draft

perf: cache empty VList Rc in VNode::default to avoid repeated heap allocation#4089
Madoshakalaka wants to merge 1 commit intomasterfrom
perf/vnode-default-avoid-allocation

Conversation

@Madoshakalaka
Copy link
Copy Markdown
Member

No description provided.

…llocation

VNode::default() is called on every mem::take() during reconciliation.
Previously each call heap-allocated a new Rc<VList>. Use a thread_local
to cache a single Rc<VList> and reuse it via Rc::clone (refcount bump only).
@Madoshakalaka Madoshakalaka added performance A-yew Area: The main yew crate labels Mar 29, 2026
@github-actions
Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 3aad31b):

https://yew-rs-api--pr4089-perf-vnode-default-a-byvsziqq.web.app

(expires Sun, 05 Apr 2026 14:40:30 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link
Copy Markdown

Benchmark - core

Yew Master

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.127 ns      │ 2.438 ns      │ 2.13 ns       │ 2.139 ns      │ 100     │ 1000000000

Pull Request

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.155 ns      │ 2.176 ns      │ 2.161 ns      │ 2.162 ns      │ 100     │ 1000000000

@github-actions
Copy link
Copy Markdown

Size Comparison

Details
examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 100.857 100.857 0 0.000%
boids 168.449 168.575 +0.126 +0.075%
communication_child_to_parent 94.074 94.074 0 0.000%
communication_grandchild_with_grandparent 105.915 105.915 0 0.000%
communication_grandparent_to_grandchild 102.256 102.256 0 0.000%
communication_parent_to_child 91.485 91.485 0 0.000%
contexts 105.974 105.974 0 0.000%
counter 86.797 86.797 0 0.000%
counter_functional 88.832 88.832 0 0.000%
dyn_create_destroy_apps 90.711 90.824 +0.113 +0.125%
file_upload 99.812 99.925 +0.113 +0.113%
function_delayed_input 94.814 94.814 0 0.000%
function_memory_game 173.664 173.777 +0.113 +0.065%
function_router 395.766 395.879 +0.113 +0.029%
function_todomvc 164.958 165.071 +0.113 +0.069%
futures 235.550 235.552 +0.002 +0.001%
game_of_life 105.098 105.211 +0.113 +0.108%
immutable 259.622 259.731 +0.109 +0.042%
inner_html 81.340 81.340 0 0.000%
js_callback 109.961 110.073 +0.112 +0.102%
keyed_list 180.405 180.519 +0.113 +0.063%
mount_point 84.713 84.713 0 0.000%
nested_list 113.662 113.772 +0.110 +0.097%
node_refs 92.085 92.226 +0.141 +0.153%
password_strength 1718.926 1718.926 0 0.000%
portals 93.557 93.686 +0.129 +0.138%
router 366.408 366.521 +0.113 +0.031%
suspense 113.961 114.074 +0.113 +0.099%
timer 88.942 88.942 0 0.000%
timer_functional 99.368 99.368 0 0.000%
todomvc 142.660 142.773 +0.113 +0.079%
two_apps 86.710 86.710 0 0.000%
web_worker_fib 136.456 136.569 +0.113 +0.083%
web_worker_prime 187.638 187.638 0 0.000%
webgl 83.486 83.596 +0.109 +0.131%

✅ None of the examples has changed their size significantly.

@github-actions
Copy link
Copy Markdown

Benchmark - SSR

Yew Master

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 270.382 280.776 271.717 3.192
Hello World 10 461.129 470.916 464.537 2.914
Function Router 10 38950.698 39687.508 39314.329 264.126
Concurrent Task 10 1005.353 1007.025 1006.281 0.560
Many Providers 10 1025.544 1088.734 1047.524 17.698

Pull Request

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 270.388 272.364 270.763 0.586
Hello World 10 445.593 456.823 448.823 3.272
Function Router 10 39097.878 39458.926 39256.082 98.197
Concurrent Task 10 1004.779 1006.893 1006.262 0.783
Many Providers 10 1028.364 1055.890 1037.511 9.872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-yew Area: The main yew crate performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant