perf(state-store): reuse unchanged read snapshots

Keep the operation lock while validating bigint file identity and reuse
only snapshots produced by successful trusted static SELECTs. Avoid
reloading and exporting unchanged databases on repeated public reads.

Retain conservative comparison for generic SQL, including RETURNING and
PRAGMA writes, and invalidate reuse after transactions, exports or errors.
Cover cache invalidation, cross-process visibility, Windows device IDs,
reentrant partial writes, lock contention and independent result objects.

Validate 188 focused tests per environment on WSL Node 22.22.3 and native
Windows Node 22.15.0/24.16.0, plus 38 related WSL tests. Paired warm-read
benchmarks show 7.6-18.1x point-query speedup on 160 KiB/1.28 MiB databases.
This commit is contained in:
Yann Roberto
2026-10-09 17:04:56 +08:00
parent a6ce6fbbdb
commit 39796acf2f
5 changed files with 593 additions and 42 deletions
@@ -82,9 +82,14 @@ project into before ECC grows a dedicated full-screen HUD.
## State Store Concurrency And Recovery
ECC's file-backed state store serializes each synchronous query or transaction
with a sibling `<database>.ecc-state.lock` file. It reloads the latest database
under that lock and publishes successful writes before releasing it. Queries
use one snapshot; closing a handle never writes an older snapshot back.
with a sibling `<database>.ecc-state.lock` file. It checks the current database
under that lock and publishes successful writes before releasing it. A handle
can reuse its last successful read snapshot when the file identity, size, and
modification/change timestamps match. Fixed SELECTs in the query API avoid
reloading or exporting an unchanged database; query results are still computed
afresh. Generic SQL, transactions, exports, and failed operations invalidate
reuse. Changes from another writer trigger a reload on the next operation.
Queries use one snapshot; closing a handle never writes an older snapshot back.
All concurrent writers must use this adapter; older ECC versions and external
SQLite writers do not participate in this locking protocol.