Performance: quadratic memmove when batching FSRS memory state updates
- Lingua principale
- Rust
- Stelle
- 30.5k
- Fork
- 3.2k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
## Motivation
In `update_memory_state_for_cards_with_items` (`rslib/src/scheduler/fsrs/memory_state.rs`),
cards are sent to `fsrs.memory_state_batch` in batches of 1000 via the local
`ChunkIntoVecs` helper, which builds each batch with `drain(..chunk_size)`.
`Vec::drain` on a prefix removes from the front and shifts every remaining
element down, so batching a collection of N cards performs roughly
`N^2 / (2 * chunk_size)` element moves — and this is done on three parallel
vectors (`to_update`, `fsrs_items`, `starting_states`).
## Proposed change
Consume the vectors with `into_iter()` and take each batch off the front of
the iterator, so the remaining elements are never touched. This makes the
batching linear in the number of cards.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.