-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Improve performance of stats revlog entries with memory state #3866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of stats revlog entries with memory state #3866
Conversation
dae
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance improvements are always appreciated! ❤️
| historical_retention: f32, | ||
| ignore_revlogs_before: TimestampMillis, | ||
| ) -> Result<Option<FsrsItemForMemoryState>> { | ||
| ) -> Result<(Option<FsrsItemForMemoryState>, Option<Vec<RevlogEntry>>)> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return value implies that one can be Some and one can be None, which is not the case. And FsrsItemForMemoryState is already a custom struct for holding the return value. Would it make sense to add a filtered_revlogs field to FsrsItemForMemoryState, and keep the return value here the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation requires the minimal modification of the current code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I figured it out. Now the filtered_revlogs has been included in FsrsItemForMemoryState.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think that's cleaner :-) If we find ourselves adding any further args to fsrs_item_for_memory_state() in the future, we'll probably want to do the same input struct treatment as you did over in the fsrs-rs crate.
This PR optimizes the memory state calculation in the FSRS scheduler by calculating all historical memory states at once instead of recalculating them incrementally for each review log entry.
Changes
fsrs_item_for_memory_state()to return both the item and filtered revlog entriesImplementation Details
The main change is in the
card_stats_with_memoryfunction, which now uses a more efficient approach:The
fsrs_item_for_memory_state()function was modified to return both the item and filtered revlog entries, which allows for proper mapping of memory states to review log entries.Benefits