Skip to content

Cache positive OSV hits#19038

Merged
woodruffw merged 11 commits into
ww/sync-mal-guardfrom
ww/audit-cache
Apr 20, 2026
Merged

Cache positive OSV hits#19038
woodruffw merged 11 commits into
ww/sync-mal-guardfrom
ww/audit-cache

Conversation

@woodruffw

@woodruffw woodruffw commented Apr 17, 2026

Copy link
Copy Markdown
Member

Summary

WIP. Atop #18936. See also #18781 and #18506.

The basic idea here is to add a layer of (manual) caching to our OSV interactions, but only for "positive" hits -- it's OK for us to cache actual successful lookups of (name, version) pairs to identifiers, but failed lookups should never be cached to prevent us from presenting false negatives to users.

Test Plan

The functionality itself here is referentially transparent, so the existing tests confirm that it works.

Separately, in terms of benchmarking, I did a profiling build and ran with:

hyperfine -i --warmup 3 './target/profiling/uv audit --project /path/to/project' './target/profiling/uv audit --no-cache  --project /path/to/project'

...on a project with 198 dependencies and 4 found vulnerabilities.

On a local machine I get about a 35% speedup with the warm caching pathway, for a total runtime of ~750ms on average. The remaining runtime is almost entirely dominated by the single (minimally cacheable) POST we perform against OSV.

Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw self-assigned this Apr 17, 2026
@woodruffw woodruffw added enhancement New feature or improvement to existing functionality preview Experimental behavior labels Apr 17, 2026
Signed-off-by: William Woodruff <william@astral.sh>
Comment thread crates/uv-audit/src/service/osv.rs Outdated
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw marked this pull request as ready for review April 20, 2026 15:07
@woodruffw woodruffw requested a review from konstin April 20, 2026 15:07
Comment thread crates/uv-audit/src/service/osv.rs Outdated
Comment thread crates/uv-audit/src/service/osv.rs Outdated
Comment thread crates/uv-audit/src/service/osv.rs Outdated
Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw requested a review from konstin April 20, 2026 17:09
.map_err(|e| Error::Url(self.base_url.clone(), e))?;
let batch_response: QueryBatchResponse = self
.client
.uncached()

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.

Can you add a comment on the uncached here?

Comment thread crates/uv-audit/src/service/osv.rs Outdated
/// Fetch a full vulnerability record by ID from OSV.
///
/// Caching is handled transparently by the [`CachedClient`] middleware using
/// a synthetic `Cache-Control: max-age=3600` header, since OSV itself does

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.

This needs to be also updated

Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw merged commit 1910d4c into ww/sync-mal-guard Apr 20, 2026
4 checks passed
@woodruffw woodruffw deleted the ww/audit-cache branch April 20, 2026 18:48
woodruffw added a commit that referenced this pull request Apr 20, 2026
## Summary

~~WIP.~~ Atop #18936. See also #18781 and #18506.

The basic idea here is to add a layer of ~~(manual)~~ caching to our OSV
interactions, but only for "positive" hits -- it's OK for us to cache
actual successful lookups of `(name, version)` pairs to identifiers, but
failed lookups should never be cached to prevent us from presenting
false negatives to users.

## Test Plan

The functionality itself here is referentially transparent, so the
existing tests confirm that it works.

Separately, in terms of benchmarking, I did a profiling build and ran
with:

```bash
hyperfine -i --warmup 3 './target/profiling/uv audit --project /path/to/project' './target/profiling/uv audit --no-cache  --project /path/to/project'
```

...on a project with 198 dependencies and 4 found vulnerabilities. 

On a local machine I get about a 35% speedup with the warm caching
pathway, for a total runtime of ~750ms on average. The remaining runtime
is almost entirely dominated by the single (minimally cacheable) POST we
perform against OSV.

---------

Signed-off-by: William Woodruff <william@astral.sh>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to existing functionality preview Experimental behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants