Skip to content

Commit 3aad31b

Browse files
committed
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<VList>. Use a thread_local to cache a single Rc<VList> and reuse it via Rc::clone (refcount bump only).
1 parent 3cbf219 commit 3aad31b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/yew/src/virtual_dom/vnode.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ impl VNode {
106106

107107
impl Default for VNode {
108108
fn default() -> Self {
109-
VNode::VList(Rc::new(VList::default()))
109+
thread_local! {
110+
static EMPTY_VLIST: Rc<VList> = Rc::new(VList::default());
111+
}
112+
VNode::VList(EMPTY_VLIST.with(Rc::clone))
110113
}
111114
}
112115

0 commit comments

Comments
 (0)