From 2d1b387a4c30b45e56d949ab64534efc47dda0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 4 Sep 2017 13:17:45 +0200 Subject: [PATCH 1/2] style: Avoid dropping the other threads' TLS contexts too early. When collecting style statistics, we have this path that moves the TLS contexts to be dropped before the local context. Since destroying the TLS context runs the sequential task queue, that means that sequential tasks would be executed sooner than usual, before we drop the main thread TLS context. Since we have that reuse of the main thread context's bloom filter, and some tasks end up creating one (Servo_StyleSet_GetBaseComputedValuesForElement, I'm looking at you), we may borrow the bloom filter before we're done with it on the traversal code path. This was hitting on YouTube, when DUMP_STYLE_STATISTICS was used. --- components/style/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/style/driver.rs b/components/style/driver.rs index 568338c009b..b2bbacfefcf 100644 --- a/components/style/driver.rs +++ b/components/style/driver.rs @@ -115,7 +115,7 @@ where let mut aggregate = mem::replace(&mut context.thread_local.statistics, Default::default()); let parallel = maybe_tls.is_some(); - if let Some(tls) = maybe_tls { + if let Some(ref mut tls) = maybe_tls { let slots = unsafe { tls.unsafe_get() }; aggregate = slots.iter().fold(aggregate, |acc, t| { match *t.borrow() { From b81f6b32864e080c0fc6b019d8f2584924e8f1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 4 Sep 2017 13:23:56 +0200 Subject: [PATCH 2/2] style: Avoid unnecessarily using Borrow. --- components/style/driver.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/style/driver.rs b/components/style/driver.rs index b2bbacfefcf..c6370d012e5 100644 --- a/components/style/driver.rs +++ b/components/style/driver.rs @@ -13,7 +13,6 @@ use parallel; use parallel::{DispatchMode, WORK_UNIT_MAX}; use rayon; use scoped_tls::ScopedTLS; -use std::borrow::Borrow; use std::collections::VecDeque; use std::mem; use time; @@ -120,7 +119,7 @@ where aggregate = slots.iter().fold(aggregate, |acc, t| { match *t.borrow() { None => acc, - Some(ref cx) => &cx.borrow().statistics + &acc, + Some(ref cx) => &cx.statistics + &acc, } }); }