FORENSIC OPTIMIZATION OF SPACED REPETITION LOGIC

01/19/2026 // SEVERITY: HIGH // TARGET: OPEN-SOURCE SRS ENGINE (FLASHCORE)

Situation

A local-first Spaced Repetition engine implementing FSRS incurred a compounding latency tax: each card review required replaying prior review history to reconstruct stability/difficulty before scheduling the next interval. As decks matured, scheduling behavior degraded into per-review linear work (O(N)), and the runtime path carried heavyweight ML dependencies that were not required for deterministic scheduling.

Finding

Forensic analysis isolated the bottleneck to state non-persistence: stability/difficulty were recomputed instead of persisted as first-class card state, creating redundant work and increasing the risk of undetected algorithmic drift. The performance failure mode was repeatable and verifiable with differential evidence (Class D): measured before/after timings and immutable build artifacts.

Impact

The scheduler was refactored to compute next intervals from cached/persisted state, eliminating history replay and restoring constant-time scheduling (O(1)) for mature datasets. Result: ~500x speedup on high-history workloads and a materially smaller runtime dependency surface (removal of torch/transformers), reducing cold-start, memory pressure, and supply-chain exposure.

Remediation

Implemented explicit state persistence semantics (DuckDB-backed) and gated the algorithmic pivot behind an auditable verification chain: CI-produced performance diffs, provenance artifacts, and immutable evidence links aligned to AIV enforcement. Outcome: the optimization is not just faster; it is provably verified.