esp32·adblocker·rebornblocklist storage format

Bucket-split 40-bit hash table architecture for 800,000+ wildcard domain storage in PSRAM.

Why 40-Bit Bucket-Split?

To fit nearly a million domains onto an embedded microcontroller, domains are stored as hashes rather than variable-length strings. The challenge with hashing is false-positive collisions where a legitimate domain's hash collides with a blocked entry. By increasing discrimination from 32-bit to 40-bit bucket-split hashing, the false-positive probability is drastically eliminated while reducing RAM footprint:

Metric32-bit Hash40-bit Bucket-Split
Per-probe False Positive Rate1.8 × 10-47.1 × 10-7
Per-query False Positive (4 suffixes)~1 in 1,500~1 in 350,000
Memory per Entry4 bytes3 bytes (+ 256 KB index)
Probes per Suffix Lookup~20 (binary search over n)~4 (search within one bucket)

The bucket index carries the top 16 bits as array position rather than stored data, achieving higher discrimination with 25% fewer bytes per entry.

In-Memory Data Layout

h40    = fmix64(fnv1a64(domain)) >> 24        40 bits total
bucket = h40 >> 24                            16 bits -> index slot
rem    = h40 & 0xFFFFFF                       24 bits -> stored remainder (3 bytes BE)

The live in-memory table is stored as a single contiguous allocation in PSRAM, allowing an atomic pointer swap when a reload completes:

+---------------------------+
| idx[65537] : uint32_t     |  262,148 bytes   idx[b]   = start offset of bucket b
|                           |                  idx[b+1] = end offset of bucket b
+---------------------------+                  idx[65536] = total entry count
| entries : 3 bytes each    |  3 * N bytes     big-endian 24-bit remainders,
|                           |                  sorted ascending within each bucket
+---------------------------+

Lookup Pipeline

When resolving a domain (e.g. sub.ad.tracker.com):

  1. Compute 40-bit hash for the exact qname and its parent wildcards (e.g. ad.tracker.com, tracker.com).
  2. Extract the 16-bit bucket number and read idx[bucket] and idx[bucket+1].
  3. Binary-search that bucket slice for the 3-byte remainder. Because average bucket occupancy is only ~12 entries, search terminates within ~4 probes, typically fitting within a single CPU cache line.

Snapshot Persistence

On boot, if a FAT32 MicroSD card is present with a valid snapshot, the pre-sorted binary image is streamed directly into PSRAM in ~21 seconds, completely bypassing upstream feed downloads and sorting.