open-spaced-repetition / fsrs-rs

FSRS for Rust, including Optimizer and Scheduler
https://crates.io/crates/fsrs
BSD 3-Clause "New" or "Revised" License
185 stars 19 forks source link

Speed up optimal_retention() #168

Closed L-M-Sherlock closed 8 months ago

L-M-Sherlock commented 8 months ago

It's ~25% faster than before, especially when the learn_span is long.

The time complexity of simulate() is O(kn^2), where k is learn_limit and n is learn_span. It costs ~30s to find the optimal retention with learn_span=3650 and learn_limit=10. In previous implementation, it costs ~40s.

cargo test --release -- optimal_retention::tests::optimal_retention

It's not recommended to set a learn_span greater than 3650.

It costs ~250s to find the optimal retention with learn_span=10000.

I hope it is the last improvement on FSRS-rs before the release of Anki 24.04. @dae