Skip to content

perf: build the full-playlist cache from YouTube's own batches, not a re-download - #681

Merged
KrX3D merged 1 commit into
mainfrom
perf/full-cache-from-native
Aug 29, 2026
Merged

perf: build the full-playlist cache from YouTube's own batches, not a re-download#681
KrX3D merged 1 commit into
mainfrom
perf/full-cache-from-native

Conversation

@KrX3D

@KrX3D KrX3D commented Aug 29, 2026

Copy link
Copy Markdown
Owner

The cache works — but almost the entire wait before it was self-inflicted:

19:50:42.395 .. 19:50:43.128   YouTube delivers every batch     0.73s
19:50:45.006 .. 19:50:52.963   our collector re-fetches them    8.0s
19:50:52.966   full_cache.stored -> reloading
19:50:53.135   full_cache.injected

YouTube had the whole playlist at 43.128. The collector then spent 8s re-downloading exactly that at 2.5s per request before the reload could happen — so the helpers sat on screen ~10s instead of ~1s.

adblock.js already intercepts every continuation response before filtering, so the raw items are taken straight from there. When a response arrives with no continuation token the playlist is complete: cache and reload immediately, no extra network work.

The hook sits before filterContinuationItems deliberately — after it, an all-watched batch is reduced to the single kept helper.

Also cancels the background collector once the native path completes (flag cleared on navigation and at each collection start, so a finished playlist can't block the next one). The collector is still kept for playlists that aren't fully watched, where YouTube only fetches on scroll and the prefetch still does real work.

Expected: full_cache.from_nativestoredreloadinginjected about a second after opening, with batch_collect.cancelled instead of eight seconds of batch_fetched.

… re-download

The cache worked on-device, but the wait before it did was almost entirely
self-inflicted:

  19:50:42.395 .. 19:50:43.128   YouTube delivers every batch      0.73s
  19:50:45.006 .. 19:50:52.963   our collector re-fetches them     8.0s
  19:50:52.966   full_cache.stored -> reloading
  19:50:53.135   full_cache.injected

YouTube had the entire playlist in hand at 43.128. The collector then spent
eight seconds re-downloading exactly that, paced at 2.5s per request, and
only then could the reload happen — so the helper tiles sat on screen for
about ten seconds instead of one.

adblock.js already intercepts every continuation response before it filters
them, so the raw items can be taken straight from there. noteContinuationBatch
accumulates them, and when a response arrives carrying no continuation token
the playlist is complete: cache it and reload immediately, with no extra
network work at all.

The hook is placed BEFORE filterContinuationItems deliberately — after it,
an all-watched batch is reduced to the single kept helper.

Also cancels the background collector once the native path has completed,
since it would otherwise keep issuing requests for data already held. The
flag is cleared on navigation and at the start of each collection, so a
finished playlist cannot block collection on the next one.

The collector is still worth keeping for playlists that are NOT fully
watched: there YouTube only fetches as the user scrolls, so the accumulator
would fill slowly and the prefetch still does useful work.
@KrX3D
KrX3D merged commit 14683d4 into main Aug 29, 2026
3 checks passed
@KrX3D
KrX3D deleted the perf/full-cache-from-native branch August 29, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant