Repository navigation
perf(tui): session browse cache for instant Nav kind switches - #88
Merged
Merged
Conversation
Switching Nav kinds re-fetched the whole browse every time, so returning to a kind you'd already loaded blanked the list until the round trip landed. Cache browse results for the TUI session, keyed by (kind, active filter), and repaint from cache immediately while a normal background browse refreshes the list (stale-while-revalidate). - Selection is restored by identity ((kind, id), not index), so a reordered refresh keeps the right row highlighted; a vanished row falls back to the top. - Filtered and unfiltered lists are separate cache keys, so clearing a `/` filter snaps back to the full list instantly. - Race-safe: every cache-backed switch still dispatches a Browse, which bumps browse_gen via stamp_request_ids, so the background refresh supersedes any in-flight browse of the prior kind and the stale guard drops the loser before it can touch the cache. Switching to Recent invalidates in-flight browses so a late response can't repopulate the cleared list. - The cache is dropped on profile switch to avoid cross-instance data bleed. BrowseComplete now carries the filter that was actually fetched so the response lands in the right cache entry.
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
Switching Nav kinds re-fetched the whole browse every time, so returning to a kind you'd already loaded blanked the list until the round trip landed. This caches browse results for the TUI session, keyed by
(kind, active filter), and repaints from cache immediately while a normal background browse refreshes the list (stale-while-revalidate).Behavior
Browsestill runs and adopts the fresh result when it lands.(kind, id), not a row index, so a reordered refresh keeps the right row highlighted; a row that's gone falls back to the top./filter snaps back to the full list instantly.Correctness (the race story)
Browsecommand, andstamp_request_idsbumpsbrowse_genfor it — so the background refresh supersedes any in-flight browse of the prior kind, andis_current_browse(req)drops the loser.BrowseCompletestale-guard runs beforeadopt_fresh_browse, so a superseded response can't poison the cache.invalidate_browse_requests(bumpsbrowse_genpast any in-flight browse), so a late response can't repopulate the cleared list.BrowseCompletenow carries the filter that was actually fetched, so the response lands in the correct cache entry.Tests
3 new pure-handler tests over the existing scaffold:
cached_browse_repaints_immediately_and_refreshes_in_background(instant repaint + backgroundBrowsedispatched + prior selection restored),browse_cache_keeps_filtered_and_unfiltered_lists_separate,recent_invalidates_in_flight_browse(late response can't repopulate Recent).Plus the profile-switch test now asserts the cache is dropped.
Verification
fmtclean;clippy --all-targetsclean on--all-featuresand--no-default-features; 1142 all-features / 1047 no-default tests pass, 0 failed.Notes
BROWSE_CAProws — but distinct filter strings accumulate for the session. A soft cap is easy to add later if marathon sessions with many filters become a concern.