From fad5447838b65288b942b90cd3a018e88889b889 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sat, 19 Apr 2025 16:18:01 -0400 Subject: [PATCH] Use swap_remove when unrooting DOM objects. (#36617) Profiling from #36609 showed this is an easy win. Ordering of our root list does not matter, so swap_remove is a constant time operation compared to a linear time one that caused memmove to appear in profiles with lots of unrooting. Testing: Existing WPT tests will cover this change. Fixes: Part of #36609. Signed-off-by: Josh Matthews --- components/script_bindings/root.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/script_bindings/root.rs b/components/script_bindings/root.rs index 51bc979908f..3d0378f0df1 100644 --- a/components/script_bindings/root.rs +++ b/components/script_bindings/root.rs @@ -412,7 +412,7 @@ impl RootCollection { .rposition(|r| std::ptr::addr_eq(*r as *const (), object as *const ())) { Some(idx) => { - roots.remove(idx); + roots.swap_remove(idx); }, None => panic!("Can't remove a root that was never rooted!"), }