Binary Slab Cache Format
To make repeat scans fast, Canontra v0.4.0 caches file fingerprints, compact per-file graph summaries (FileGraphSummary), and whole-repository CSR graphs in .canontra/cache.bin using the CNTR\x07 binary format (Canontra.Cache.SlabV7).
Warm lookups complete in 6.0 us (lookupSlabV7BinaryBS), decoding 10 modules runs in 216.7 us (decodeSlabV7Binary), and rebuilding whole-repo graphs from cached summaries takes 112.9 us (F_WCG) and 65.6 us (F_WDF) without re-parsing unchanged files (RQ18).
File Layout (CNTR\x07)
Section titled “File Layout (CNTR\x07)”+-------------------------------------------------------------------+| 0x0000 - 0x001F (32 bytes) Global Header ("CNTR" + version 7) |+-------------------------------------------------------------------+| 0x0020 - 0x081F (2,048 B) 256-Way L1 Radix Jump Table |+-------------------------------------------------------------------+| 0x0820 - ... 64-Byte CacheRecordV6 Table || (capacity = max(512, numEntries)) |+-------------------------------------------------------------------+| slabStartOffset - EOF 4KB Page-Aligned Payload Slabs || (9-tier bundle + FileGraphSummary || + multi-page spanning for large mods|| + per-page IEEE 802.3 CRC-32C) || + Optional Repo WholeRepoBundle/CSR |+-------------------------------------------------------------------+1. Global Header (0x0000 to 0x001F, 32 Bytes)
Section titled “1. Global Header (0x0000 to 0x001F, 32 Bytes)”- Magic and Version:
"CNTR"followed byword16LE 7(CNTR\x07) and aword16LErepository-slab flag (1when whole-repoWholeRepoBundleand CSR graphs are appended). - Counts and Offsets:
numEntries(Word32),capacity(Word32,max(512, numEntries)),globalCRC(Word32IEEE 802.3 CRC-32C covering the header and radix table),repoOff(Word32), andrepoLen(Word32). - Header Check:
verifySlabV7HeaderCRCvalidates the header before reading any records.
2. 256-Way L1 Radix Jump Table (0x0020 to 0x081F)
Section titled “2. 256-Way L1 Radix Jump Table (0x0020 to 0x081F)”A 2,048-byte jump table (256 * 8 bytes) indexed by the top byte of each 64-bit fastPathHash64 path hash (h >> 56). Lookups jump directly to the matching bucket in O(1) without scanning earlier entries.
3. 64-Byte CacheRecordV6 File Table (0x0820 to 0x0820 + capacity * 64)
Section titled “3. 64-Byte CacheRecordV6 File Table (0x0820 to 0x0820 + capacity * 64)”Each entry is a fixed 64-byte (sizeOf _ = 64) record aligned to a CPU cache line (Storable):
| Byte Offset | Field | Type | Purpose |
|---|---|---|---|
0x00 .. 0x07 |
crPathHash |
Word64 |
64-bit FNV-1a / SwissTable normalized path hash |
0x08 .. 0x0F |
crMTimeSec |
Word64 |
File modification timestamp (seconds) |
0x10 .. 0x13 |
crMTimeNano |
Word32 |
File modification timestamp (nanoseconds) |
0x14 .. 0x17 |
crFileSize |
Word32 |
Source file size in bytes |
0x18 .. 0x1B |
crSlabOffset |
Word32 |
Byte offset into payload slab region |
0x1C .. 0x1F |
crSlabLength |
Word32 |
Byte length of stored payload |
0x20 .. 0x27 |
crF4DigestHead |
Word64 |
First 64 bits of composite F4 hash |
0x28 .. 0x2F |
crFlags |
Word64 |
Bit flagMultiPagePayload = 1 when payload spans multiple 4KB pages |
0x30 .. 0x37 |
crReserved1 |
Word64 |
Cache-line alignment padding (0) |
0x38 .. 0x3F |
crReserved2 |
Word64 |
Cache-line alignment padding (0) |
4. FileGraphSummary and 4KB CRC-32C Pages
Section titled “4. FileGraphSummary and 4KB CRC-32C Pages”Each file slab stores its 9-tier FingerprintBundle plus an optional binary FileGraphSummary (encodeFileGraphSummary / decodeFileGraphSummary):
- Normalized file path and module name
- Imported modules and JS/TS re-export tuples
- Exported
GlobalSymboldeclarations - Intra-module
CallEdgeandCallFlowSiterecords
During warm or single-file-dirty runs of canontra repo --cache or canontra snap mark, buildWholeRepoCallGraphFromSummaries and buildWholeRepoDataFlowFromSummaries combine cached summaries for untouched files with fresh summaries for edited files, avoiding a full-repo re-parse.
- Multi-Page Spanning and Bit-Rot Recovery: Large modules span contiguous 4KB CRC-32C pages (
flagMultiPagePayload = 1).decodeSlabV7Resilient/readSlabV7FileResilientdrop only damaged 4KB pages and keep all healthy entries intact. - Automatic Legacy Upgrade:
readAnySlabCacheForV7reads existingCNTR\x06(SlabV6) andCNTR\x05(PagedCache) files seamlessly on upgrade. - Windows File-Lock Safety: Cache writes stage to a temporary
.tmp.<pid>file and rename atomically viaatomicSwapWithRetry_(exponential backoff with jitter) to survive transient Windows Defender or SearchIndexer locks.
Cache Inspection Commands
Section titled “Cache Inspection Commands”canontra cache info # Inspect record counts, slab pages, and statisticscanontra cache verify # Check header and every 4KB page CRC-32C checksumcanontra cache prune # Remove entries for deleted filescanontra cache clean # Delete .canontra/cache.bin