Remove sync_wrapper dep in favor of Mutex (#514)
We unwrap the stream exactly once per response, and we know that case will be uncontended for the same reason `SyncWrapper` works: `into_reader()` takes `self`, so it must have exclusive ownership. Uncontended mutexes are extremely cheap. This saves us a dependency at a trivial performance cost.
This commit is contained in:
committed by
GitHub
parent
4bb6d3a4db
commit
8a32cae507
@@ -35,7 +35,6 @@ socks = { version = "0.3", optional = true }
|
|||||||
serde = { version = "1", optional = true }
|
serde = { version = "1", optional = true }
|
||||||
serde_json = { version = "1", optional = true }
|
serde_json = { version = "1", optional = true }
|
||||||
encoding_rs = { version = "0.8", optional = true }
|
encoding_rs = { version = "0.8", optional = true }
|
||||||
sync_wrapper = { version = "0.1" }
|
|
||||||
cookie_store = { version = "0.16", optional = true, default-features = false, features = ["preserve_order"] }
|
cookie_store = { version = "0.16", optional = true, default-features = false, features = ["preserve_order"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
webpki = { version = "0.22", optional = true }
|
webpki = { version = "0.22", optional = true }
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use std::io::{self, Read};
|
use std::io::{self, Read};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::sync::Mutex;
|
||||||
use std::{fmt, io::BufRead};
|
use std::{fmt, io::BufRead};
|
||||||
|
|
||||||
use chunked_transfer::Decoder as ChunkDecoder;
|
use chunked_transfer::Decoder as ChunkDecoder;
|
||||||
use sync_wrapper::SyncWrapper;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::body::SizedReader;
|
use crate::body::SizedReader;
|
||||||
@@ -69,7 +69,7 @@ pub struct Response {
|
|||||||
// Boxed to avoid taking up too much size.
|
// Boxed to avoid taking up too much size.
|
||||||
unit: Box<Unit>,
|
unit: Box<Unit>,
|
||||||
// Boxed to avoid taking up too much size.
|
// Boxed to avoid taking up too much size.
|
||||||
stream: SyncWrapper<Box<Stream>>,
|
stream: Mutex<Box<Stream>>,
|
||||||
/// The redirect history of this response, if any. The history starts with
|
/// The redirect history of this response, if any. The history starts with
|
||||||
/// the first response received and ends with the response immediately
|
/// the first response received and ends with the response immediately
|
||||||
/// previous to this one.
|
/// previous to this one.
|
||||||
@@ -291,7 +291,7 @@ impl Response {
|
|||||||
self.length
|
self.length
|
||||||
};
|
};
|
||||||
|
|
||||||
let stream = self.stream.into_inner();
|
let stream = self.stream.into_inner().unwrap();
|
||||||
let unit = self.unit;
|
let unit = self.unit;
|
||||||
let result = stream.set_read_timeout(unit.agent.config.timeout_read);
|
let result = stream.set_read_timeout(unit.agent.config.timeout_read);
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
@@ -514,7 +514,7 @@ impl Response {
|
|||||||
status,
|
status,
|
||||||
headers,
|
headers,
|
||||||
unit: Box::new(unit),
|
unit: Box::new(unit),
|
||||||
stream: SyncWrapper::new(Box::new(stream.into())),
|
stream: Mutex::new(Box::new(stream.into())),
|
||||||
history: vec![],
|
history: vec![],
|
||||||
length,
|
length,
|
||||||
compression,
|
compression,
|
||||||
@@ -524,7 +524,7 @@ impl Response {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn into_written_bytes(self) -> Vec<u8> {
|
pub fn into_written_bytes(self) -> Vec<u8> {
|
||||||
// Deliberately consume `self` so that any access to `self.stream` must be non-shared.
|
// Deliberately consume `self` so that any access to `self.stream` must be non-shared.
|
||||||
self.stream.into_inner().written_bytes()
|
self.stream.into_inner().unwrap().written_bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user