Consider to improve the performance of card_stats()

card.card_stats_data() became slow after Feat/forgetting curve in card info by L-M-Sherlock · Pull Request #3437 · ankitects/anki · GitHub because it computes the memory state for each revlog. For card with 40+ revlogs, it costs ~400ms to return the result. It’s not perceivable when opening the card info page. But it slows down add-ons which use card_stats_data() to get the revlogs of thoustands of cards significantly.

I have some solutions:

  1. add an option to card_stats() to control whether to compute the memory state for each revlog.
  2. add a new api to fetch the revlogs of given card.
  3. refactor the calculation method of historical memory states to reduce the computation complexity from O(n^2) to O(n). It requires a refactor on FSRS-rs part.

@dae, sorry for bothering you. I want your advice before I work on the new PR.

2 Likes

3 would be nice in the long run, but either 1 or 2 works for me. 2 is probably cleaner, as card_stats_data() was mainly intended for the UI.

3 Likes

Done:

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.