Skip to content

compact: cache each archive's referenced objects to speed up analysis#9896

Merged
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:cache-archive-objects
Jul 11, 2026
Merged

compact: cache each archive's referenced objects to speed up analysis#9896
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:cache-archive-objects

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

analyze_archives() scans every archive's items on each run just to collect the object ids it references. Cache that per archive in the repo as cache/referenced-by-archive., so an unchanged archive is not scanned again next time; caches of archives that no longer exist are dropped.

The cache stores the referenced object ids (id -> plaintext size) plus the archive's source file count and content size, both counted per occurrence, so the reported statistics are identical to a full scan. Integrity is protected by a sha256 appended to the serialized blob.

@ThomasWaldmann

ThomasWaldmann commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

Did a quick test:

  • remote repository on google drive (SLOW)
  • stats:
Overall statistics, considering all 5 archives in this repository:
Source data size was 213 GB in 2164621 files.
Deduplicated size is 47 GB.
Deduplication factor is 0.22.
Repository size is 42 GB in 281212 objects.
Compression factor is 0.88.
  • compact runtime (no cache, before this change): 7:37
  • compact runtime (2nd run, with cache): 2:04

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.18%. Comparing base (bc3f14d) to head (398ff20).
⚠️ Report is 8 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/archiver/compact_cmd.py 85.71% 9 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9896      +/-   ##
==========================================
- Coverage   85.32%   85.18%   -0.14%     
==========================================
  Files          93       93              
  Lines       15671    15793     +122     
  Branches     2387     2400      +13     
==========================================
+ Hits        13372    13454      +82     
- Misses       1598     1633      +35     
- Partials      701      706       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

analyze_archives() scans every archive's items on each run just to collect the
object ids it references. Cache that per archive in the repo as
cache/referenced-by-archive.<id>, so an unchanged archive is not scanned again
next time; caches of archives that no longer exist are dropped.

The cache stores the referenced object ids (id -> plaintext size) plus the
archive's source file count and content size, both counted per occurrence, so
the reported statistics are identical to a full scan. Integrity is protected by
a sha256 appended to the serialized blob.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ThomasWaldmann ThomasWaldmann force-pushed the cache-archive-objects branch from 5bfa787 to 398ff20 Compare July 11, 2026 10:10
@ThomasWaldmann ThomasWaldmann merged commit 8ac9e77 into borgbackup:master Jul 11, 2026
18 of 19 checks passed
@ThomasWaldmann ThomasWaldmann deleted the cache-archive-objects branch July 11, 2026 11:49
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