Skip to content

feat(cache): precompute weak ETag per cache entry#351

Merged
c-thiel merged 1 commit into
mainfrom
ct/pre-compute-wek-etag-per-cache-entry
Jul 16, 2026
Merged

feat(cache): precompute weak ETag per cache entry#351
c-thiel merged 1 commit into
mainfrom
ct/pre-compute-wek-etag-per-cache-entry

Conversation

@c-thiel

@c-thiel c-thiel commented Jul 16, 2026

Copy link
Copy Markdown
Member

Store a weak ETag opaque tag on CacheItem::Found, computed once when the rendered (config-templated) bytes are cached. Consumers can serve it as W/"{etag}" and answer conditional requests without re-hashing the body on every request — the DuckDB WASM assets are 30-40 MB.

Use xxh3 (as the catalog already does for loadTable ETags) instead of the std DefaultHasher: ~4x faster on the WASM blobs and, unlike SipHash, a fixed algorithm — so the tag stays stable across Rust releases and won't spuriously invalidate caches on a toolchain bump.

Summary by CodeRabbit

  • New Features

    • Added stable weak ETags to cached file responses.
    • ETags now change when rendered content changes, improving cache validation.
  • Bug Fixes

    • Ensured repeated requests for unchanged cached content consistently receive the same ETag.

Store a weak ETag opaque tag on CacheItem::Found, computed once when the
rendered (config-templated) bytes are cached. Consumers can serve it as
`W/"{etag}"` and answer conditional requests without re-hashing the body
on every request — the DuckDB WASM assets are 30-40 MB.

Use xxh3 (as the catalog already does for loadTable ETags) instead of the
std DefaultHasher: ~4x faster on the WASM blobs and, unlike SipHash, a
fixed algorithm — so the tag stays stable across Rust releases and won't
spuriously invalidate caches on a toolchain bump.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The cache adds weak ETags to found entries, computes them from rendered bytes using xxh3, and validates stability for identical content and changes caused by forwarded prefixes.

Changes

Weak ETag caching

Layer / File(s) Summary
ETag contract and generation
console-rs/Cargo.toml, console-rs/src/cache.rs
Adds the xxhash-rust dependency, extends CacheItem::Found with an ETag, and generates hexadecimal tags from rendered bytes.
Cache integration and validation
console-rs/src/cache.rs
FileCache::get_file stores computed ETags and tests stable values for repeated loads plus differing values across forwarded prefixes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit hashes bytes at night,
Weaving tags in silver light.
Same files keep their badge in place,
New prefixes change the trace.
Hop, hop—cache checks pass just right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: precomputing weak ETags for cache entries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ct/pre-compute-wek-etag-per-cache-entry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
console-rs/src/cache.rs (1)

36-39: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider padding the hex string to a consistent length.

While ETags are opaque and variable lengths are perfectly valid, using {:016x} ensures that the generated tag always has a uniform 16-character width, even if the resulting hash contains leading zeros.

♻️ Proposed refactor
 fn weak_etag_tag(data: &[u8]) -> String {
-    format!("{:x}", xxhash_rust::xxh3::xxh3_64(data))
+    format!("{:016x}", xxhash_rust::xxh3::xxh3_64(data))
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@console-rs/src/cache.rs` around lines 36 - 39, Update weak_etag_tag to format
the xxh3_64 hash as a zero-padded 16-character lowercase hexadecimal string
using the existing hash value, ensuring every generated ETag has consistent
width.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@console-rs/src/cache.rs`:
- Around line 36-39: Update weak_etag_tag to format the xxh3_64 hash as a
zero-padded 16-character lowercase hexadecimal string using the existing hash
value, ensuring every generated ETag has consistent width.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 24bff53c-4279-46fe-a0c9-17096206f6f9

📥 Commits

Reviewing files that changed from the base of the PR and between 34618c5 and 4258386.

📒 Files selected for processing (2)
  • console-rs/Cargo.toml
  • console-rs/src/cache.rs

@c-thiel
c-thiel merged commit 4ea3416 into main Jul 16, 2026
7 checks passed
@c-thiel
c-thiel deleted the ct/pre-compute-wek-etag-per-cache-entry branch July 16, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant