Skip to content

Refresh HTTP cache policies in place - #22052

Merged
charliermarsh merged 6 commits into
mainfrom
charlie/refresh-cache-policy-in-place
Sep 30, 2026
Merged

charliermarsh merged 6 commits into
mainfrom
charlie/refresh-cache-policy-in-place

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

We now update the HTTP cache policy in place on a 304 response, avoiding a rewrite of the cached payload. The format change bumps the six cache buckets containing HTTP responses.

Warm-cache benchmarks on Linux/ext4, with 96 entries and 16 concurrent requests per batch (c9dab42be → 1562e401b, using SeaHash):

Warm-cache workload Main PR Paired change
304 refresh, 256 KiB 80.39 ms 9.84 ms 87.4% faster
304 refresh, 1 MiB 323.20 ms 17.59 ms 94.6% faster
Fresh reads, 4 KiB 0.711 ms 0.712 ms Approximately unchanged
Fresh reads, 256 KiB 2.140 ms 2.112 ms 2.9% faster
Fresh reads, 1 MiB 7.529 ms 7.698 ms No clear difference

Comment thread crates/uv-cache/src/lib.rs Resolved
Comment thread crates/uv-client/src/cached_client.rs Resolved
Comment thread crates/uv-client/src/cached_client.rs Resolved
@charliermarsh charliermarsh added the internal A refactor or improvement that is not user-facing label Sep 28, 2026
@astral-sh-bot

astral-sh-bot Bot commented Sep 28, 2026

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the main base revision.

  • Added tests: 9
  • Removed tests: 1
  • Changed suites: 2
uv-client: +3 / -0

Added:

  • uv-client::cached_client::tests::cache_trailer_corruption_is_rejected
  • uv-client::cached_client::tests::interrupted_policy_writes_never_accept_a_mixed_policy
  • uv-client::cached_client::tests::policy_can_grow_and_shrink_in_place

Removed: none

uv-client::it: +6 / -1

Added:

  • uv-client::it::cached_client::delayed_revalidation_cannot_modify_replaced_payload
  • uv-client::it::cached_client::overlapping_policy_updates_are_refetched
  • uv-client::it::cached_client::reject_invalid_cache_lengths
  • uv-client::it::cached_client::revalidation_of_readonly_entry
  • uv-client::it::cached_client::revalidation_updates_only_policy
  • uv-client::it::cached_client::torn_policy_is_refetched

Removed:

  • uv-client::it::cached_client::reject_overflowing_cache_policy_length

let path = cache_entry.path().to_path_buf();
let span = Span::current();
let payload = tokio::task::spawn_blocking(move || {
span.in_scope(|| {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can give this its own scope so it shows up separately in traces

Comment thread crates/uv-client/src/cached_client.rs Outdated
/// Reading the format is done via an `AlignedVec` so that `rkyv` can correctly
/// read the archived representation of the data blob. The cache policy is
/// split into its own `AlignedVec` allocation.
/// Each file contains the payload, a random 16-byte generation ID, the archived

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the ID for?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My read of below is that we use it to prevent an accidental clobber of another cache write, i.e. due to concurrency. But calling it a "generation" is arguably confusing since that implies an incrementing value, not a random ID like it currently is 🙂

Specifically here: https://github.com/astral-sh/uv/pull/22052/changes#diff-a327e08abfc6c0f1a83a8c92ad294c17f1b410f5133b1e81ccbdc76008c1f8b0R1057

@charliermarsh
charliermarsh merged commit f060188 into main Sep 30, 2026
89 of 90 checks passed
@charliermarsh
charliermarsh deleted the charlie/refresh-cache-policy-in-place branch September 30, 2026 02:07
@codspeed

codspeed Bot commented Sep 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×3.8

⚡ 1 improved benchmark
✅ 71 untouched benchmarks
⏩ 28 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ WallTime revalidate_shared 328.9 ms 85.9 ms ×3.8

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing charlie/refresh-cache-policy-in-place (ccaca30) with main (831a46a)

Open in CodSpeed

Footnotes

  1. 28 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

charliermarsh added a commit that referenced this pull request Oct 1, 2026
We revert the cache-format stack so `main` retains the 0.12 cache
formats and bucket versions. These changes are deferred to 0.13.

This reverts the following PRs together, including the six cache bucket
bumps and the serialization and Windows lock-name changes that depend on
them:

- #22052: Refresh HTTP cache policies in place
- #22059: Store source distribution revision IDs inline
- #22060: Remove the legacy hash digest cache representation
- #22061: Derive serialization for cached artifact records
- #22062: Use bounded wheel cache lock names on Windows
- #22078: Pack HTTP cache policy flags and optional integers
- #22079: Align cached HTTP policies within the payload buffer
charliermarsh added a commit that referenced this pull request Oct 1, 2026
Reapplies #22052 for 0.13.

We now update the HTTP cache policy in place on a 304 response, avoiding
a rewrite of the cached payload. The format change bumps the six cache
buckets containing HTTP responses.

Original benchmarks from #22052 on Linux/ext4, with 96 entries and 16
concurrent requests per batch (`c9dab42be` → `1562e401b`, using
SeaHash):

| Warm-cache workload | Main | PR | Paired change |
|---|---:|---:|---:|
| 304 refresh, 256 KiB | 80.39 ms | 9.84 ms | 87.4% faster |
| 304 refresh, 1 MiB | 323.20 ms | 17.59 ms | 94.6% faster |
| Fresh reads, 4 KiB | 0.711 ms | 0.712 ms | Approximately unchanged |
| Fresh reads, 256 KiB | 2.140 ms | 2.112 ms | 2.9% faster |
| Fresh reads, 1 MiB | 7.529 ms | 7.698 ms | No clear difference |
zanieb pushed a commit that referenced this pull request Oct 7, 2026
Reapplies #22052 for 0.13.

We now update the HTTP cache policy in place on a 304 response, avoiding
a rewrite of the cached payload. The format change bumps the six cache
buckets containing HTTP responses.

Original benchmarks from #22052 on Linux/ext4, with 96 entries and 16
concurrent requests per batch (`c9dab42be` → `1562e401b`, using
SeaHash):

| Warm-cache workload | Main | PR | Paired change |
|---|---:|---:|---:|
| 304 refresh, 256 KiB | 80.39 ms | 9.84 ms | 87.4% faster |
| 304 refresh, 1 MiB | 323.20 ms | 17.59 ms | 94.6% faster |
| Fresh reads, 4 KiB | 0.711 ms | 0.712 ms | Approximately unchanged |
| Fresh reads, 256 KiB | 2.140 ms | 2.112 ms | 2.9% faster |
| Fresh reads, 1 MiB | 7.529 ms | 7.698 ms | No clear difference |
zanieb pushed a commit that referenced this pull request Oct 9, 2026
Reapplies #22052 for 0.13.

We now update the HTTP cache policy in place on a 304 response, avoiding
a rewrite of the cached payload. The format change bumps the six cache
buckets containing HTTP responses.

Original benchmarks from #22052 on Linux/ext4, with 96 entries and 16
concurrent requests per batch (`c9dab42be` → `1562e401b`, using
SeaHash):

| Warm-cache workload | Main | PR | Paired change |
|---|---:|---:|---:|
| 304 refresh, 256 KiB | 80.39 ms | 9.84 ms | 87.4% faster |
| 304 refresh, 1 MiB | 323.20 ms | 17.59 ms | 94.6% faster |
| Fresh reads, 4 KiB | 0.711 ms | 0.712 ms | Approximately unchanged |
| Fresh reads, 256 KiB | 2.140 ms | 2.112 ms | 2.9% faster |
| Fresh reads, 1 MiB | 7.529 ms | 7.698 ms | No clear difference |
astral-automations-bot Bot pushed a commit to astral-sh/uv-dev that referenced this pull request Oct 10, 2026
Reapplies astral-sh#22052 for 0.13.

We now update the HTTP cache policy in place on a 304 response, avoiding
a rewrite of the cached payload. The format change bumps the six cache
buckets containing HTTP responses.

Original benchmarks from astral-sh#22052 on Linux/ext4, with 96 entries and 16
concurrent requests per batch (`c9dab42be` → `1562e401b`, using
SeaHash):

| Warm-cache workload | Main | PR | Paired change |
|---|---:|---:|---:|
| 304 refresh, 256 KiB | 80.39 ms | 9.84 ms | 87.4% faster |
| 304 refresh, 1 MiB | 323.20 ms | 17.59 ms | 94.6% faster |
| Fresh reads, 4 KiB | 0.711 ms | 0.712 ms | Approximately unchanged |
| Fresh reads, 256 KiB | 2.140 ms | 2.112 ms | 2.9% faster |
| Fresh reads, 1 MiB | 7.529 ms | 7.698 ms | No clear difference |

This branch was previously deployed

1 inactive deployment
automations — ccaca304 Deployed Sep 30, 2026 by charliermarsh via review / security review #48396
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user-facing performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants