Skip to content

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).

+-------------------------------------------------------------------+
| 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 by word16LE 7 (CNTR\x07) and a word16LE repository-slab flag (1 when whole-repo WholeRepoBundle and CSR graphs are appended).
  • Counts and Offsets: numEntries (Word32), capacity (Word32, max(512, numEntries)), globalCRC (Word32 IEEE 802.3 CRC-32C covering the header and radix table), repoOff (Word32), and repoLen (Word32).
  • Header Check: verifySlabV7HeaderCRC validates 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)

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 GlobalSymbol declarations
  • Intra-module CallEdge and CallFlowSite records

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 / readSlabV7FileResilient drop only damaged 4KB pages and keep all healthy entries intact.
  • Automatic Legacy Upgrade: readAnySlabCacheForV7 reads existing CNTR\x06 (SlabV6) and CNTR\x05 (PagedCache) files seamlessly on upgrade.
  • Windows File-Lock Safety: Cache writes stage to a temporary .tmp.<pid> file and rename atomically via atomicSwapWithRetry_ (exponential backoff with jitter) to survive transient Windows Defender or SearchIndexer locks.
Terminal window
canontra cache info # Inspect record counts, slab pages, and statistics
canontra cache verify # Check header and every 4KB page CRC-32C checksum
canontra cache prune # Remove entries for deleted files
canontra cache clean # Delete .canontra/cache.bin