From 3aad31bbde20243e69b69cca4ecd1a177df027eb Mon Sep 17 00:00:00 2001 From: Matt Yan Date: Sun, 29 Mar 2026 23:36:43 +0900 Subject: [PATCH] perf: cache empty VList Rc in VNode::default to avoid repeated heap allocation VNode::default() is called on every mem::take() during reconciliation. Previously each call heap-allocated a new Rc. Use a thread_local to cache a single Rc and reuse it via Rc::clone (refcount bump only). --- packages/yew/src/virtual_dom/vnode.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/yew/src/virtual_dom/vnode.rs b/packages/yew/src/virtual_dom/vnode.rs index baf12f857a3..e544c821976 100644 --- a/packages/yew/src/virtual_dom/vnode.rs +++ b/packages/yew/src/virtual_dom/vnode.rs @@ -106,7 +106,10 @@ impl VNode { impl Default for VNode { fn default() -> Self { - VNode::VList(Rc::new(VList::default())) + thread_local! { + static EMPTY_VLIST: Rc = Rc::new(VList::default()); + } + VNode::VList(EMPTY_VLIST.with(Rc::clone)) } }