sqlite point-lookup benchmarks
sqlite point-lookup benchmarks
a warm-cache point-lookup benchmark against stock SQLite measures SQLite's defaults, not its engine. driven properly, SQLite is about sixteen times faster on the same workload than in its default configuration, and a 24× lead for a new engine shrank to about 1.5× once all three defaults below were fixed.
the three defaults
in order of impact:
- per-statement locking. outside an explicit transaction, every
sqlite3_stepacquires and releases the file lock, which is fcntl syscalls per lookup (about 9.5 µs/op measured). holding a read transaction (BEGIN...COMMIT) around the loop brought it to about 2 µs/op. - the page cache.
cache_sizedefaults to about 2 MB, and any larger working set thrashes it. size it to the file (PRAGMA cache_size = -Nfor N KiB) before comparing warm performance. - no mmap.
PRAGMA mmap_sizedefaults to 0, so every page miss is apreadplus a copy into SQLite's cache. with mmap, warm reads come from the OS page cache without the copy.
most applications run the default configuration, so a fair comparison reports both.
what moves the number
random point lookups are memory-latency bound. instruction-level micro-optimizations (varint fast paths, slimmer probe parsing) measure as noise; cache misses and indirection are what to attack. the harness rules (identical input, a parity checksum, warmups, medians) are in benchmark validity.
how a page cache can beat SQLite's own is in page caches; how a value's size changes SQLite's B-tree layout is in compact point-read indexes. see also zig database patterns and mst hot paths (small sorted nodes prefer a linear scan).
sources
Did you enjoy this article?
Recommend it — Standard Reader surfaces well-loved writing to more readers across the network.