|
| 1 | +# TASK-029: Performance Hotspot Closure (schema/data version + persistent prepares) |
| 2 | + |
| 3 | +## Status |
| 4 | +- [ ] Planned |
| 5 | +- [ ] Assigned |
| 6 | +- [ ] In Progress |
| 7 | +- [ ] Blocked (reason: ...) |
| 8 | +- [ ] Complete |
| 9 | + |
| 10 | +## Priority |
| 11 | +high |
| 12 | + |
| 13 | +## Assigned To |
| 14 | +subagent (general) |
| 15 | + |
| 16 | +## Parent Docs / Cross-links |
| 17 | +- Gap backlog: `research/zig-cr/92-gap-backlog.md` ("Remaining Gaps → Performance Optimizations") |
| 18 | +- Hotspot analysis: `research/zig-cr/11-performance-hotspots.md` |
| 19 | +- Likely code hotspots: `zig/src/stmt_cache.zig`, `zig/src/changes_vtab.zig`, `zig/src/ffi/api.zig` |
| 20 | + |
| 21 | +## Description |
| 22 | +Close the remaining post-MVP performance gaps that are explicitly tracked but not yet implemented: |
| 23 | + |
| 24 | +1) `PRAGMA schema_version` keyed invalidation caching (avoid unnecessary union rebuild / stmt recreation) |
| 25 | +2) `PRAGMA data_version` check amortization (avoid polling/pragma spam on hot loops) |
| 26 | +3) Prefer `sqlite3_prepare_v3(..., SQLITE_PREPARE_PERSISTENT)` for long-lived statements |
| 27 | + |
| 28 | +This task is intentionally narrow: improve hot-path behavior without changing query semantics. |
| 29 | + |
| 30 | +## Files to Modify |
| 31 | +- `zig/src/stmt_cache.zig` |
| 32 | +- `zig/src/changes_vtab.zig` |
| 33 | +- `zig/src/ffi/api.zig` (if prepare_v3 / flags wiring needed) |
| 34 | +- `research/zig-cr/92-gap-backlog.md` (check off items + add brief notes) |
| 35 | + |
| 36 | +## Acceptance Criteria |
| 37 | +- [ ] `stmt_cache` exposes an explicit "schema version changed" signal that callers can use to invalidate cached derived artifacts. |
| 38 | +- [ ] `changes_vtab` avoids rebuilding or repreparing union statements when schema_version unchanged. |
| 39 | +- [ ] `PRAGMA data_version` checks are amortized (e.g. once per transaction / once per cursor scan loop) with no correctness regressions. |
| 40 | +- [ ] If supported by the SQLite target, long-lived statements are prepared using `sqlite3_prepare_v3` with `SQLITE_PREPARE_PERSISTENT`. |
| 41 | +- [ ] `make test-unit` and `make test-parity` pass. |
| 42 | + |
| 43 | +## Progress Log |
| 44 | +### 2025-12-14 |
| 45 | +- Task created during gap review; not yet started |
| 46 | + |
| 47 | +## Completion Notes |
| 48 | +[fill in when done] |
0 commit comments