diff --git a/crates/puffin-client/src/cached_client.rs b/crates/puffin-client/src/cached_client.rs index 514d5e80b0e51..e4b59c80b9485 100644 --- a/crates/puffin-client/src/cached_client.rs +++ b/crates/puffin-client/src/cached_client.rs @@ -43,14 +43,15 @@ enum CachedResponse { /// There was no prior cached response or the cache was outdated /// /// The cache policy is `None` if it isn't storable - ModifiedOrNew(Response, Option), + ModifiedOrNew(Response, Option>), } /// Serialize the actual payload together with its caching information #[derive(Debug, Deserialize, Serialize)] pub struct DataWithCachePolicy { pub data: Payload, - cache_policy: CachePolicy, + // The cache policy is large (448 bytes at time of writing), reduce the stack size + cache_policy: Box, } /// Custom caching layer over [`reqwest::Client`] using `http-cache-semantics`. @@ -232,14 +233,14 @@ impl CachedClient { debug!("Found not-modified response for: {url}"); CachedResponse::NotModified(DataWithCachePolicy { data: cached.data, - cache_policy: new_policy, + cache_policy: Box::new(new_policy), }) } AfterResponse::Modified(new_policy, _parts) => { debug!("Found modified response for: {url}"); CachedResponse::ModifiedOrNew( res, - new_policy.is_storable().then_some(new_policy), + new_policy.is_storable().then(|| Box::new(new_policy)), ) } } @@ -272,7 +273,7 @@ impl CachedClient { CachePolicy::new(&converted_req.into_parts().0, &converted_res.into_parts().0); Ok(CachedResponse::ModifiedOrNew( res, - cache_policy.is_storable().then_some(cache_policy), + cache_policy.is_storable().then(|| Box::new(cache_policy)), )) } } diff --git a/crates/puffin-client/src/flat_index.rs b/crates/puffin-client/src/flat_index.rs index 120951e8cf075..ec0153b210c13 100644 --- a/crates/puffin-client/src/flat_index.rs +++ b/crates/puffin-client/src/flat_index.rs @@ -2,7 +2,7 @@ use std::collections::btree_map::Entry; use std::collections::BTreeMap; use std::path::PathBuf; -use futures::StreamExt; +use futures::{FutureExt, StreamExt}; use reqwest::Response; use rustc_hash::FxHashMap; use tracing::{debug, info_span, instrument, warn, Instrument}; @@ -121,6 +121,7 @@ impl<'a> FlatIndexClient<'a> { .collect(); Ok(files) } + .boxed() .instrument(info_span!("parse_flat_index_html", url = % url)) }; let files = cached_client diff --git a/crates/puffin-client/src/registry_client.rs b/crates/puffin-client/src/registry_client.rs index 837b5af0c06c2..3a2301c9dab97 100644 --- a/crates/puffin-client/src/registry_client.rs +++ b/crates/puffin-client/src/registry_client.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use async_http_range_reader::{AsyncHttpRangeReader, AsyncHttpRangeReaderError}; use async_zip::tokio::read::seek::ZipFileReader; -use futures::TryStreamExt; +use futures::{FutureExt, TryStreamExt}; use reqwest::{Client, ClientBuilder, Response, StatusCode}; use reqwest_retry::policies::ExponentialBackoff; use reqwest_retry::RetryTransientMiddleware; @@ -206,6 +206,7 @@ impl RegistryClient { } } } + .boxed() .instrument(info_span!("parse_simple_api", package = %package_name)) }; let result = self @@ -335,6 +336,7 @@ impl RegistryClient { })?; Ok(metadata) } + .boxed() .instrument(info_span!("read_metadata_range_request", wheel = %filename)) };