servo: Merge #12890 - Lessen pressure on the thread-local RNG (from nox:rng-pressure); r=Manishearth
authorAnthony Ramine <n.oxyde@gmail.com>
Tue, 16 Aug 2016 05:19:37 -0500
changeset 339501 295e871b0b449b441fab6ac794e4c0ebd121e2c4
parent 339500 d3fceb86ab3b7d6a123f7fe1aa175e044d642fee
child 339502 2db67712b2a87b5c208738a2df29e9112f4456e4
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth
servo: Merge #12890 - Lessen pressure on the thread-local RNG (from nox:rng-pressure); r=Manishearth Source-Repo: https://github.com/servo/servo Source-Revision: 2b74e94b730cfbf35dda7d5bc5775810a578eebc
servo/components/net/fetch/methods.rs
servo/components/net/http_loader.rs
--- a/servo/components/net/fetch/methods.rs
+++ b/servo/components/net/fetch/methods.rs
@@ -29,16 +29,17 @@ use net_traits::request::{Type, Origin, 
 use net_traits::response::{HttpsState, TerminationReason};
 use net_traits::response::{Response, ResponseBody, ResponseType};
 use resource_thread::CancellationListener;
 use std::collections::HashSet;
 use std::fs::File;
 use std::io::Read;
 use std::iter::FromIterator;
 use std::mem::swap;
+use std::ops::Deref;
 use std::rc::Rc;
 use std::sync::mpsc::{channel, Sender, Receiver};
 use unicase::UniCase;
 use url::{Origin as UrlOrigin, Url};
 use util::thread::spawn_named;
 use uuid;
 
 pub type Target = Option<Box<FetchTaskTarget + Send>>;
@@ -947,27 +948,29 @@ fn http_network_fetch(request: Rc<Reques
 
     // Step 4
     let factory = NetworkHttpRequestFactory {
         connector: connection,
     };
     let url = request.current_url();
     let cancellation_listener = CancellationListener::new(None);
 
-    let request_id = uuid::Uuid::new_v4().simple().to_string();
+    let request_id = devtools_chan.as_ref().map(|_| {
+        uuid::Uuid::new_v4().simple().to_string()
+    });
 
     // XHR uses the default destination; other kinds of fetches (which haven't been implemented yet)
     // do not. Once we support other kinds of fetches we'll need to be more fine grained here
     // since things like image fetches are classified differently by devtools
     let is_xhr = request.destination == Destination::None;
     let wrapped_response = obtain_response(&factory, &url, &request.method.borrow(),
                                            &request.headers.borrow(),
                                            &cancellation_listener, &request.body.borrow(), &request.method.borrow(),
                                            &request.pipeline_id.get(), request.redirect_count.get() + 1,
-                                           &devtools_chan, &request_id, is_xhr);
+                                           request_id.as_ref().map(Deref::deref), is_xhr);
 
     let pipeline_id = request.pipeline_id.get();
     let mut response = Response::new();
     match wrapped_response {
         Ok((res, msg)) => {
             response.url = Some(url.clone());
             response.status = Some(res.response.status);
             response.raw_status = Some(res.response.status_raw().clone());
@@ -991,17 +994,17 @@ fn http_network_fetch(request: Rc<Reques
                             if let Some(m) = msg {
                                 send_request_to_devtools(m, &sender);
                             }
 
                             // --- Tell devtools that we got a response
                             // Send an HttpResponse message to devtools with the corresponding request_id
                             if let Some(pipeline_id) = pipeline_id {
                                 send_response_to_devtools(
-                                    &sender, request_id.into(),
+                                    &sender, request_id.unwrap(),
                                     meta_headers.map(Serde::into_inner),
                                     meta_status.map(Serde::into_inner),
                                     pipeline_id);
                             }
                         }
 
                         loop {
                             match read_block(&mut res) {
--- a/servo/components/net/http_loader.rs
+++ b/servo/components/net/http_loader.rs
@@ -40,16 +40,17 @@ use profile_traits::time::{ProfilerCateg
 use profile_traits::time::{TimerMetadataReflowType, TimerMetadataFrameType};
 use resource_thread::{CancellationListener, send_error, start_sending_sniffed_opt, AuthCache, AuthCacheEntry};
 use std::borrow::ToOwned;
 use std::boxed::FnBox;
 use std::collections::HashSet;
 use std::error::Error;
 use std::fmt;
 use std::io::{self, Cursor, Read, Write};
+use std::ops::Deref;
 use std::sync::mpsc::Sender;
 use std::sync::{Arc, RwLock};
 use time;
 use time::Tm;
 #[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
 use tinyfiledialogs;
 use url::{Url, Position};
 use util::prefs::PREFS;
@@ -739,18 +740,17 @@ pub fn obtain_response<A>(request_factor
                           url: &Url,
                           method: &Method,
                           request_headers: &Headers,
                           cancel_listener: &CancellationListener,
                           data: &Option<Vec<u8>>,
                           load_data_method: &Method,
                           pipeline_id: &Option<PipelineId>,
                           iters: u32,
-                          devtools_chan: &Option<Sender<DevtoolsControlMsg>>,
-                          request_id: &str,
+                          request_id: Option<&str>,
                           is_xhr: bool)
                           -> Result<(A::R, Option<ChromeToDevtoolsControlMsg>), LoadError>
                           where A: HttpRequest + 'static  {
     let null_data = None;
     let response;
     let connection_url = replace_hosts(&url);
     let mut msg;
 
@@ -803,20 +803,20 @@ pub fn obtain_response<A>(request_factor
         }
 
         let send_start = precise_time_ms();
 
         let maybe_response = req.send(request_body);
 
         let send_end = precise_time_ms();
 
-        msg = if devtools_chan.is_some() {
+        msg = if let Some(request_id) = request_id {
             if let Some(pipeline_id) = *pipeline_id {
                 Some(prepare_devtools_request(
-                    request_id.clone().into(),
+                    request_id.into(),
                     url.clone(), method.clone(), headers,
                     request_body.clone(), pipeline_id, time::now(),
                     connect_end - connect_start, send_end - send_start, is_xhr))
             } else {
                 None
             }
         } else {
             None
@@ -963,17 +963,19 @@ pub fn load<A, B>(load_data: &LoadData,
         let mut request_headers = if iters == 1 {
             let mut combined_headers = load_data.headers.clone();
             combined_headers.extend(load_data.preserved_headers.iter());
             combined_headers
         } else {
             load_data.preserved_headers.clone()
         };
 
-        let request_id = uuid::Uuid::new_v4().simple().to_string();
+        let request_id = devtools_chan.as_ref().map(|_| {
+            uuid::Uuid::new_v4().simple().to_string()
+        });
 
         modify_request_headers(&mut request_headers, &doc_url,
                                &user_agent, load_data.referrer_policy,
                                &mut referrer_url);
 
         // https://fetch.spec.whatwg.org/#concept-http-network-or-cache-fetch step 11
         if load_data.credentials_flag {
             if !block_cookies {
@@ -987,17 +989,18 @@ pub fn load<A, B>(load_data: &LoadData,
         //if there is a new auth header then set the request headers with it
         if let Some(ref auth_header) = new_auth_header {
             request_headers.set(auth_header.clone());
         }
 
         let (response, msg) =
             try!(obtain_response(request_factory, &doc_url, &method, &request_headers,
                                  &cancel_listener, &load_data.data, &load_data.method,
-                                 &load_data.pipeline_id, iters, &devtools_chan, &request_id, false));
+                                 &load_data.pipeline_id, iters,
+                                 request_id.as_ref().map(Deref::deref), false));
 
         process_response_headers(&response, &doc_url, &http_state.cookie_jar, &http_state.hsts_list, &load_data);
 
         //if response status is unauthorized then prompt user for username and password
         if response.status() == StatusCode::Unauthorized &&
            response.headers().get_raw("WWW-Authenticate").is_some() {
             let (username_option, password_option) =
                 ui_provider.input_username_and_password(doc_url.as_str());
@@ -1087,17 +1090,17 @@ pub fn load<A, B>(load_data: &LoadData,
         metadata.referrer = referrer_url.clone();
 
         // --- Tell devtools that we got a response
         // Send an HttpResponse message to devtools with the corresponding request_id
         // TODO: Send this message even when the load fails?
         if let Some(pipeline_id) = load_data.pipeline_id {
             if let Some(ref chan) = devtools_chan {
                 send_response_to_devtools(
-                    &chan, request_id,
+                    &chan, request_id.unwrap(),
                     metadata.headers.clone().map(Serde::into_inner),
                     metadata.status.clone().map(Serde::into_inner),
                     pipeline_id);
             }
         }
         if response.status().class() == StatusClass::Redirection {
             continue;
         } else {