perf(tracking): gate cleanup_old behind 24h interval by guyoron1 · Pull Request #2615 · rtk-ai/rtk · GitHub
Skip to content

perf(tracking): gate cleanup_old behind 24h interval#2615

Open
guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:perf/tracking-cleanup-gating
Open

perf(tracking): gate cleanup_old behind 24h interval#2615
guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:perf/tracking-cleanup-gating

Conversation

@guyoron1

Copy link
Copy Markdown

Summary

Fixes #2208

cleanup_old() ran two DELETE ... WHERE timestamp < ? scans on every record() and record_parse_failure() call, adding ~7ms of synchronous SQLite I/O to every RTK command — violating the <10ms startup target.

This PR gates cleanup behind a 24-hour interval using a new meta key-value table:

  • On each record() call, a single SELECT on the 1-row meta table checks last_cleanup (~0.05ms)
  • Cleanup only runs if >24 hours have elapsed since the last run
  • 90-day data retention means daily cleanup is more than sufficient

Performance impact:

  • Before: ~7ms added to every command (two DELETE table scans)
  • After: ~0.05ms on 99.9% of calls (one SELECT on PK), ~7ms once per 24h

Changes:

  • Add CLEANUP_INTERVAL_HOURS constant (24h) to constants.rs
  • Add meta table (key TEXT PRIMARY KEY, value TEXT) in schema setup
  • Replace cleanup_old() with maybe_cleanup() — checks last_cleanup timestamp before running DELETEs
  • Use let _ = for cleanup calls (INSERT already succeeded; cleanup failure shouldn't break recording)

Test plan

  • cargo fmt --all — no issues
  • cargo clippy --all-targets — zero warnings
  • cargo test --all — all 2246 tests pass
  • New test: test_maybe_cleanup_skips_when_recent — verifies old records survive when last_cleanup is fresh
  • New test: test_maybe_cleanup_runs_when_stale — verifies old records are deleted when last_cleanup >24h ago

cleanup_old() ran two DELETE scans on every record() call, adding ~7ms
of synchronous SQLite I/O to every command. Gate it behind a meta table
timestamp so it runs at most once per 24 hours.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(tracking): enabled tracking adds ~7ms synchronous SQLite write to every command's hot path

1 participant