cog_open() turns on DuckDB's enable_http_metadata_cache. Every view and query had been re-requesting the same HTTP file metadata.
R/cache.R, previously a stub, keeps the ten metadata tables (about 3 MB) in USCOGDATA_CACHE_DIR/corpus/. A cached copy is used only while its sha256 matches the manifest, and a download is checked before it is moved into place. On any failure the session reads remotely, as before, and prints a message. A local corpus is never cached. The yearly partitions stay remote.
NEWS and README updated.
Measured against the public corpus (2026-11-12, one run each)
before
first session
later sessions
session open
5.6 s
1.76 s
0.38 s
first one-year query
1.2 s
1.16 s
0.68 s
same query again
0.55 s
0.02 s
The first session's first query was not timed separately for the HTTP-metadata change alone, which measured 0.8 s.
Test plan
7 offline tests for the cache, using an injected fetch: cold, warm, stale, sha mismatch, HTTP error, missing sha, views split between cache and corpus.
cog_spending() for Madison (552025209777), 2012 and 2020: identical 46 rows and digest on this branch and on main.
CI green.
Note: profiling triggered HTTP 429 from Hugging Face's anonymous rate limit. The cache reduces requests; cog_mirror() remains the answer for heavy repeat work.
## Summary
- `cog_open()` turns on DuckDB's `enable_http_metadata_cache`. Every view and query had been re-requesting the same HTTP file metadata.
- `R/cache.R`, previously a stub, keeps the ten metadata tables (about 3 MB) in `USCOGDATA_CACHE_DIR/corpus/`. A cached copy is used only while its sha256 matches the manifest, and a download is checked before it is moved into place. On any failure the session reads remotely, as before, and prints a message. A local corpus is never cached. The yearly partitions stay remote.
- NEWS and README updated.
## Measured against the public corpus (2026-11-12, one run each)
| | before | first session | later sessions |
|---|---:|---:|---:|
| session open | 5.6 s | 1.76 s | 0.38 s |
| first one-year query | 1.2 s | 1.16 s | 0.68 s |
| same query again | 0.55 s | 0.02 s | |
The first session's first query was not timed separately for the HTTP-metadata change alone, which measured 0.8 s.
## Test plan
- [x] 7 offline tests for the cache, using an injected fetch: cold, warm, stale, sha mismatch, HTTP error, missing sha, views split between cache and corpus.
- [x] `testthat::test_local()`: 1,290 pass, 0 fail.
- [x] Live-corpus tests (`USCOGDATA_LIVE_TEST=true`): 8 pass.
- [x] `cog_spending()` for Madison (552025209777), 2012 and 2020: identical 46 rows and digest on this branch and on main.
- [ ] CI green.
Note: profiling triggered HTTP 429 from Hugging Face's anonymous rate limit. The cache reduces requests; `cog_mirror()` remains the answer for heavy repeat work.
Closes #64
🤖 Generated with [Claude Code](https://claude.com/claude-code)
On the remote path every CREATE VIEW and every query re-requested the same
file metadata over HTTP. Against the public Hugging Face corpus on 2026-11-12
(one run per arm, from this Mac), turning on DuckDB's
enable_http_metadata_cache moved:
session open 5.6 s -> 1.6 s
first one-year query 1.2 s -> 0.8 s
same query again 0.55 s -> 0.02 s
parquet_metadata_cache alone changed nothing measurable, so it stays off.
The cache is per connection, so nothing persists between sessions; that half
of #64 is still open. Live-corpus tests pass with the setting on.
Refs #64
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R/cache.R was a stub, so a remote session read the ten metadata tables
(about 3 MB) over HTTP every time. cog_open() now keeps them in
USCOGDATA_CACHE_DIR/corpus/ and points the metadata views there. A
cached file is used only while its sha256 matches the session's manifest;
a download is checked before it replaces anything. Any failure (an HTTP
error such as Hugging Face's 429, a mismatch, an unwritable directory)
falls back to remote reads with a message. A local corpus is read in place
and never cached. The yearly partitions stay remote; cog_mirror() is
still the tool for repeat work on them.
Against the public corpus, 2026-11-12, one run each, fresh cache:
session open 1.76 s cold -> 0.38 s warm
first query 1.16 s cold -> 0.68 s warm
cog_spending() for Madison (552025209777), 2012 and 2020, returns the same
46 rows and the same digest as main. Live-corpus tests pass.
Closes#64
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared
merged commit dfb5b4c711 into main2026-11-12 21:49:45 -05:00
jared
deleted branch perf/remote-metadata-cache-642026-11-12 21:49:45 -05:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
cog_open()turns on DuckDB'senable_http_metadata_cache. Every view and query had been re-requesting the same HTTP file metadata.R/cache.R, previously a stub, keeps the ten metadata tables (about 3 MB) inUSCOGDATA_CACHE_DIR/corpus/. A cached copy is used only while its sha256 matches the manifest, and a download is checked before it is moved into place. On any failure the session reads remotely, as before, and prints a message. A local corpus is never cached. The yearly partitions stay remote.Measured against the public corpus (2026-11-12, one run each)
The first session's first query was not timed separately for the HTTP-metadata change alone, which measured 0.8 s.
Test plan
testthat::test_local(): 1,290 pass, 0 fail.USCOGDATA_LIVE_TEST=true): 8 pass.cog_spending()for Madison (552025209777), 2012 and 2020: identical 46 rows and digest on this branch and on main.Note: profiling triggered HTTP 429 from Hugging Face's anonymous rate limit. The cache reduces requests;
cog_mirror()remains the answer for heavy repeat work.Closes #64
🤖 Generated with Claude Code