Optimizing SQLite Against Its Official and Academic Benchmarks

SQLite 3.54.0 development trunk

Benchmarks: speedtest1 · kvtest · TATP (OLTP) · Star Schema Benchmark (OLAP)

Published at github.com/ksenxx/sqlite-optimized · independently re-verified from a fresh clone on 8 Aug 2026

Optimized end-to-end by KISS Sorcar in under 8 hours, on a budget under $150

What this is about

SQLite is the most widely deployed database engine in the world: it ships inside every phone, every major browser, and most embedded devices. This post describes making a development build of SQLite faster on four benchmarks: the two official ones that ship with SQLite itself (speedtest1, a broad mix of ~30,000 SQL statements, and kvtest, raw blob I/O) and two standard academic workloads (TATP, a telecom-style OLTP transaction mix, and the Star Schema Benchmark, an OLAP query suite).

The problem

SQLite’s out-of-the-box configuration is deliberately conservative: it defaults to rollback-journal mode, which pays a create–write–fsync–unlink cycle on every transaction; its bytecode interpreter re-enters a giant switch statement for every opcode; and small write-ahead-log writes reach the filesystem one frame at a time. Profiling showed these costs dominate real workloads — on speedtest1 alone, roughly 45% of the runtime was journal churn.

For context: the SQLite team has spent nearly 20 years tuning this code. Their own measurements show roughly a 3.5× total CPU improvement since 2008, earned a few percent at a time. The gains described here come from trading away default conservatism (journaling mode, portability of the interpreter loop, per-frame WAL writes), not from finding waste the SQLite authors missed.

SQLite’s reputation rests on correctness and durability, so the binding constraint was to get the speed without breaking anything: every change had to produce byte-identical query results, pass the entire million-plus-case SQLite test suite, hold up under adversarial and security testing, and stay opt-in so that default builds remain untouched.

Summary

Result: a verified geometric-mean speedup of 1.59× across the four benchmarks (best case 2.06× on speedtest1). The full SQLite test suite passes: 1,032,940 test cases across all 1,462 TCL test scripts, zero errors. Benchmark results are byte-identical to the baseline, enforced by checksums on every run.

All of the work (profiling, engine changes, benchmark harness, adversarial testing, security hardening, and reviews) was carried out by KISS Sorcar in under 8 hours on a budget under $150, using claude-fable-5 for development, kimi-k3 for security hardening, and gpt-sol5.6-sol-high for independent read-only review.

Final measured results

Protocol: identical workloads, seeds, and statement mixes for every build; 3 repetitions; medians reported. The harness (benchks/bench.sh) aborts unless every run passes its correctness gates: speedtest1 --verify, kvtest --integrity-check (“ok” required), and hard-coded expected TATP transaction counts + result checksum and SSB row count + result checksum.

Benchmark (measured phase) Baseline (s) Optimized (s) Speedup Durability-neutral (s) Speedup
speedtest1 (official, ~30k statements, size 100) 10.3625.019 2.06× 5.6201.84×
TATP transaction mix (400k txns, 100k subscribers) 3.8232.016 1.90× 2.0211.89×
SSB 13 queries × 2 (1.5M-row lineorder) 2.8062.166 1.30× 2.1921.28×
kvtest blob I/O (40k × 10KB; seq + random + update) 2.7672.209 1.25× 2.2201.25×
Geometric mean 1.59× 1.54×
speedtest1 2.06× TATP (OLTP) 1.90× SSB (OLAP) 1.30× kvtest (blobs) 1.25× geometric mean 1.59×
Speedup of the optimized build over the pristine baseline (median of 3 runs; the 1× line is “no change”).

The durability-neutral column re-measures everything with synchronous=FULL in WAL mode, so a committed transaction survives power loss exactly as strongly as in the baseline’s rollback journal mode. Even under that stricter comparison the tree is 1.54× faster overall. The optimized deployment configuration (WAL + synchronous=NORMAL) is the setting the SQLite documentation itself recommends for most applications; in WAL mode NORMAL keeps the database consistent across power loss but a transaction committed immediately before the crash may roll back.

What was changed

All engine changes are opt-in compile options (default builds remain byte-for-byte the traditional code), and every changed default remains overridable at runtime by applications.

1. Write-ahead-log journaling by default (largest gain)

2. WAL write coalescing

3. Computed-goto opcode dispatch

4. Faster build and tuned defaults

How the work was verified

Reproducing the results

The complete protocol ships as benchks/README.md in the public repository. The PGO step (build_pgo.sh) is required for the full speedup — without it the CPU-bound SSB benchmark loses most of its gain (1.03× instead of 1.30×).

git clone https://github.com/ksenxx/sqlite-optimized
cd sqlite-optimized && mkdir build-base build-opt
( cd build-base && ../configure && make sqlite3.c )   # generate amalgamation
cp build-base/sqlite3.{c,h} build-opt/

benchks/build_bench.sh build-base                     # pristine baseline
benchks/bench.sh build-base baseline 3                # medians of 3 reps

. benchks/optflags.sh                                 # optimized + PGO build
benchks/build_pgo.sh build-opt $OPT_DEFS
benchks/bench.sh build-opt final 3

# upstream test suite (default build options)
( cd build-base && make testfixture && \
  ./testfixture ../test/testrunner.tcl --jobs 24 full )

Generated benchmark outputs land in benchks/results/ (gitignored; not tracked on GitHub). Reviews and audits are included in the repository: benchks/ADVERSARIAL.md, benchks/HARDENING.md, benchks/REVIEW.md. Absolute times, and therefore exact ratios, vary a few percent with machine load, thermal state, and the exact PGO profile; following the published protocol end-to-end reproduces 1.53–1.55× geomean on the same class of machine (1.50× if the PGO step is skipped). All testing so far has been on standard Linux provided by GCP; other operating systems and filesystems have not yet been benchmarked.