Repository navigation
Conversation
- Conflict list: drop rtk-ai#2579/rtk-ai#2590/rtk-ai#2615 (already flagged 07-17), add rtk-ai#2401/rtk-ai#2453 and the chunk-7 conflict cluster; note top-pick rtk-ai#2401 is a hand-port (issue #54). - Next-wave: restore recovered candidate rtk-ai#2256 (gh prompt-injection scan) dropped in distillation. Co-Authored-By: Claude Fable 5 <[email protected]>
e1d2f1b to
376afa9
Compare
376afa9 to
9af836f
Compare
cleanup_old() ran after every record() and record_parse_failure(). It is three DELETEs, each its own autocommit statement and so its own WAL commit, on top of the one the INSERT already paid: four fsyncs per recorded command on a path that runs for every rtk <cmd>, under the project's <10ms budget. Retention is 90 days, so almost every one of those sweeps deletes nothing. Gate it on last_insert_rowid(), which the INSERT just above already produced - no extra read, no clock, and an exact 1-in-N cadence rather than a probabilistic one. Because the cadence is per row written rather than per unit time, the slack is self-scaling and bounded: at most RECORD_CLEANUP_SAMPLE_RATE rows can sit past the window between sweeps, whatever the command rate. hook_decisions keeps its own sampled sweep (maybe_cleanup_hook_decisions), which is the backstop for installs whose commands are mostly denied and so rarely reach record() at all. should_sample_cleanup is not reused here: it needs a key that differs per call, and record() has none - the command text repeats verbatim across calls, and the clock is the input that function's own comment warns off. The sweep is now best-effort, matching record_hook_decision: by the time it runs the INSERT has committed, so a failing sweep must not be reported as the record itself having failed. Measured on macOS/APFS, WAL, a 5k-row history: 63-99us per record() with the sweep, 51-89us without it - 10-20us and three of the four WAL commits gone per recorded command. That is well short of the ~7ms rtk-ai#2208 measures end to end; the PRAGMA table in that issue points at journal/sync settings for the bulk of it, and this only removes the sweep's share, which grows with how expensive fsync is on the filesystem. Refs rtk-ai#2208
9af836f to
1102e9e
Compare
|
Rebased, and reworked: the It now gates on Measured here (macOS/APFS, WAL, 5k-row history): 63-99 µs per One small behaviour change is bundled in: the sweep is now best-effort (a warning on stderr) rather than failing |
Summary
Refs #2208
record()andrecord_parse_failure()rancleanup_old()after every insert. That is threeDELETEs (commands,parse_failures,hook_decisions), each its own autocommit statement and so its own WAL commit, on top of the one theINSERTalready paid: four commits per recorded command, to delete nothing almost every time (retention is 90 days).This sweeps on every 100th insert instead, gated on
last_insert_rowid(), which theINSERTjust above already produced:metatable; that would not survive theuser_version-gated migrations, which never re-run on an existing database)hook_decisionskeeps its own sampled sweep (maybe_cleanup_hook_decisions), which is the backstop for installs whose commands are mostly denied and so rarely reachrecord()The sweep is now best-effort (a warning on stderr), like
record_hook_decision: theINSERThas already committed by then, so a failed sweep should not be reported as the record failing.Measurements
macOS/APFS, WAL, 5k-row history, running the exact statements
record()runs (release build): 63-99 µs perrecord()with the sweep vs 51-89 µs without it. That is 10-20 µs and three of the four WAL commits removed per recorded command. It is well short of the ~7 ms end-to-end figure in #2208, which that issue's own PRAGMA table attributes mostly to journal/sync settings; the sweep's share grows with how expensive fsync is on the filesystem.Tests
test_record_skips_the_sweep_between_samples: a singlerecord()must not sweep (fails when the sweep runs on every call)test_record_still_sweeps_within_one_sample_window: a full window of inserts still deletes expired rowscargo fmt --all -- --check,cargo clippy --all-targets(0 warnings),cargo test --all(all pass)