0.34.6_repo_cleanup
This commit is contained in:
1 parent
ce1a90397c
commit
133d2f0f91
273 files changed
+5969
-6926
No files matched your search
Vendored
+24
-37
@@ -63,8 +63,6 @@ struct Candidate {
|
||||
plan: Plan,
|
||||
headers: HeaderMap,
|
||||
data: Vec<u8>,
|
||||
// A transformed response with one uniquely owned Bytes frame can share its
|
||||
// allocation with the downstream response, avoiding an extra Vec copy.
|
||||
shared: Option<Bytes>,
|
||||
shared_allocated: usize,
|
||||
fill_gauge: FillGauge,
|
||||
@@ -78,11 +76,9 @@ struct Candidate {
|
||||
}
|
||||
impl Candidate {
|
||||
fn finish(mut self) {
|
||||
if self
|
||||
.plan
|
||||
.expected_length
|
||||
.is_some_and(|length| self.shared.as_ref().map_or(self.data.len(), Bytes::len) != length)
|
||||
{
|
||||
if self.plan.expected_length.is_some_and(|length| {
|
||||
self.shared.as_ref().map_or(self.data.len(), Bytes::len) != length
|
||||
}) {
|
||||
let reason = if self.transformed {
|
||||
"transform_length_mismatch"
|
||||
} else {
|
||||
@@ -101,7 +97,6 @@ impl Candidate {
|
||||
self.headers.insert("date", value);
|
||||
}
|
||||
}
|
||||
// Each downstream exchange receives a new ID, never a cached origin ID.
|
||||
for name in [
|
||||
"x-request-id",
|
||||
"x-cache",
|
||||
@@ -113,9 +108,6 @@ impl Candidate {
|
||||
self.headers.remove(name);
|
||||
}
|
||||
let vary = std::mem::take(&mut self.plan.vary);
|
||||
// Keep the actual backing capacity as the HOT charge. Vec::reserve_exact
|
||||
// avoids geometric multi-MiB overshoot while Bytes::from(Vec) transfers
|
||||
// the allocation without copying.
|
||||
let (body, body_allocation) = if let Some(body) = self.shared.take() {
|
||||
(body, self.shared_allocated)
|
||||
} else {
|
||||
@@ -201,10 +193,6 @@ impl HttpBody for FillBody {
|
||||
match Pin::new(&mut this.inner).poll_frame(cx) {
|
||||
Poll::Ready(Some(Ok(frame))) => {
|
||||
let mut frame = frame;
|
||||
// Only the transformed single-frame case is eligible. Taking
|
||||
// unique ownership lets Bytes reveal its true allocation
|
||||
// capacity; we must never undercharge an arbitrary shared
|
||||
// Bytes slice that could retain a much larger parent buffer.
|
||||
if this.inner.is_end_stream() {
|
||||
if let Some(candidate) = &mut this.candidate {
|
||||
let single_frame = candidate.transformed
|
||||
@@ -216,26 +204,26 @@ impl HttpBody for FillBody {
|
||||
});
|
||||
if single_frame {
|
||||
match frame.into_data() {
|
||||
Ok(bytes) => {
|
||||
match bytes.try_into_mut() {
|
||||
Ok(mutable) => {
|
||||
let allocation = mutable.capacity();
|
||||
let bytes = mutable.freeze();
|
||||
// A very oversized backing Vec is cheaper to
|
||||
// copy into a smaller HOT allocation instead.
|
||||
let acceptable_spare = bytes.len().saturating_div(8).min(64 * 1024);
|
||||
if allocation <= bytes.len().saturating_add(acceptable_spare)
|
||||
&& allocation <= candidate.settings.max_object_bytes
|
||||
&& candidate.fill_gauge.grow(allocation, &candidate.settings)
|
||||
{
|
||||
candidate.shared = Some(bytes.clone());
|
||||
candidate.shared_allocated = allocation;
|
||||
}
|
||||
frame = Frame::data(bytes);
|
||||
Ok(bytes) => match bytes.try_into_mut() {
|
||||
Ok(mutable) => {
|
||||
let allocation = mutable.capacity();
|
||||
let bytes = mutable.freeze();
|
||||
let acceptable_spare =
|
||||
bytes.len().saturating_div(8).min(64 * 1024);
|
||||
if allocation
|
||||
<= bytes.len().saturating_add(acceptable_spare)
|
||||
&& allocation <= candidate.settings.max_object_bytes
|
||||
&& candidate
|
||||
.fill_gauge
|
||||
.grow(allocation, &candidate.settings)
|
||||
{
|
||||
candidate.shared = Some(bytes.clone());
|
||||
candidate.shared_allocated = allocation;
|
||||
}
|
||||
Err(bytes) => frame = Frame::data(bytes),
|
||||
frame = Frame::data(bytes);
|
||||
}
|
||||
}
|
||||
Err(bytes) => frame = Frame::data(bytes),
|
||||
},
|
||||
Err(original) => frame = original,
|
||||
}
|
||||
}
|
||||
@@ -243,7 +231,6 @@ impl HttpBody for FillBody {
|
||||
}
|
||||
if let Some(candidate) = &mut this.candidate {
|
||||
if candidate.shared.is_some() {
|
||||
// The cache now owns the very same backing allocation.
|
||||
} else if let Some(data) = frame.data_ref() {
|
||||
let needed = candidate.data.len().saturating_add(data.len());
|
||||
if needed <= candidate.settings.max_object_bytes {
|
||||
@@ -284,7 +271,8 @@ impl HttpBody for FillBody {
|
||||
this.candidate = None;
|
||||
} else {
|
||||
let after = candidate.data.capacity();
|
||||
let unbudgeted = after.saturating_sub(before.saturating_add(required_growth));
|
||||
let unbudgeted =
|
||||
after.saturating_sub(before.saturating_add(required_growth));
|
||||
if unbudgeted > 0
|
||||
&& !candidate.fill_gauge.grow(unbudgeted, &candidate.settings)
|
||||
{
|
||||
@@ -328,7 +316,7 @@ impl HttpBody for FillBody {
|
||||
.rejected_fills
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
this.candidate = None;
|
||||
} // Do not cache responses with trailers.
|
||||
}
|
||||
}
|
||||
if this.inner.is_end_stream() {
|
||||
this.done = true;
|
||||
@@ -391,4 +379,3 @@ impl Drop for FillBody {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user