perf(shuffle): cache the ranked library — ~2.2s per shuffle to instant - #145
Merged
Conversation
Each shuffle re-concatenated PanTS+CancerVerse (~32k rows), copied it, added sort columns, and re-ran the full quality ranking — all deterministic for the default 'all' scope. Cache the concat+sort-cols (_all_dataset_prepared) and the ranked frame per pick-size n (_ranked_all); apply recent-exclusion + the rotating offset per request on top (a defensive copy guards the shared frame). The filtered-scope path is unchanged. Turns each shuffle from 'rank 32k rows' into a slice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes shuffle much faster by caching the deterministic part of
/api/randomfor the default "all" scope.The problem (measured on the live data)
Every shuffle click rebuilt everything from scratch:
pd.concat(PanTS + CancerVerse)(~32k rows) →.copy()→ add sort columns → re-run the full quality ranking. Measured cost: 2.188s per shuffle of pure backend work.The fix
That whole chain is deterministic for scope "all" (the dataset is loaded once at startup), so:
_all_dataset_prepared()caches concat + sort-cols,_ranked_all(n)caches the quality-ranked frame per pick-sizen.The per-request bits — recent-exclusion and the rotating offset — are applied on top (with a defensive copy so the shared cached frame is never mutated). The filtered-scope path is byte-for-byte unchanged.
Verified on the server (real data)
So the first shuffle after a restart costs ~2.2s (warms the cache); every one after is instant.
py_compilepasses.