From 2ab66ce67870acfff7bf18087421013475411380 Mon Sep 17 00:00:00 2001 From: Wulan Seruniati Salim <103485830+wulanseruniati@users.noreply.github.com> Date: Sun, 22 Dec 2024 18:14:57 +0700 Subject: [PATCH] Optimize mutex usage in fetch by locking once and using scoped MutexGuard (#34737) Signed-off-by: Wulan Seruniati Salim --- components/net/fetch/methods.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index 9a7d5d203ff..3b1474c713c 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -101,17 +101,11 @@ pub type DoneChannel = Option<(TokioSender, TokioReceiver)>; pub async fn fetch(request: &mut Request, target: Target<'_>, context: &FetchContext) { // Steps 7,4 of https://w3c.github.io/resource-timing/#processing-model // rev order okay since spec says they're equal - https://w3c.github.io/resource-timing/#dfn-starttime - context - .timing - .lock() - .unwrap() - .set_attribute(ResourceAttribute::FetchStart); - context - .timing - .lock() - .unwrap() - .set_attribute(ResourceAttribute::StartTime(ResourceTimeValue::FetchStart)); - + { + let mut timing_guard = context.timing.lock().unwrap(); + timing_guard.set_attribute(ResourceAttribute::FetchStart); + timing_guard.set_attribute(ResourceAttribute::StartTime(ResourceTimeValue::FetchStart)); + } fetch_with_cors_cache(request, &mut CorsCache::default(), target, context).await; }