Rebuild a login's channel view in slices after a merge #50

Merged
namillis merged 1 commit from fix/view-rebuild-stall into main 2026-11-20 21:32:17 +00:00
Owner

With GC out of the way (#49), the one stall left in a profile of the live pool was a login's channel view rebuilding after a merge: 1.4 s, split between assignStreams (48%), sync gzip (21%) and the view loop. It runs whenever a TV asks for the list after a merge.

  • buildView's work is a generator. buildView runs it in one go as before; buildViewSliced runs it in slices of about 25 ms and gzips on zlib's threads.
  • The deferred rebuild after a merge uses the sliced build. Requests keep getting the current view until the new one is ready, and one profile never has two rebuilds at once. First builds and catch-up changes still build in one go.
  • The full stream list's JSON is the category lists' JSON joined, instead of a second stringify of ~28k streams.
  • assignStreams skips the member pass for channel objects the merge reused with the same id: the pool only reuses a channel when its streams are unchanged, so their ids are already recorded. Stream ids are still assigned before the first pause, so two builds never interleave changes to them.

On the real pool (login countries UK,US, 28,720 channels), deployed vs this branch, same view and same id state in every round:

Deployed blocks Branch, longest block
Nothing changed 1.3-2.4 s 0.2 s
After polar refreshed 1.3-2.3 s 0.3 s
After happy8k refreshed 1.3-1.9 s 0.4-0.8 s

What's left in the longest block is assignStreams itself, after a big provider refresh.

Tests: 146/146 pass.

With GC out of the way (#49), the one stall left in a profile of the live pool was a login's channel view rebuilding after a merge: 1.4 s, split between `assignStreams` (48%), sync gzip (21%) and the view loop. It runs whenever a TV asks for the list after a merge. - `buildView`'s work is a generator. `buildView` runs it in one go as before; `buildViewSliced` runs it in slices of about 25 ms and gzips on zlib's threads. - The deferred rebuild after a merge uses the sliced build. Requests keep getting the current view until the new one is ready, and one profile never has two rebuilds at once. First builds and catch-up changes still build in one go. - The full stream list's JSON is the category lists' JSON joined, instead of a second stringify of ~28k streams. - `assignStreams` skips the member pass for channel objects the merge reused with the same id: the pool only reuses a channel when its streams are unchanged, so their ids are already recorded. Stream ids are still assigned before the first pause, so two builds never interleave changes to them. On the real pool (login countries UK,US, 28,720 channels), deployed vs this branch, same view and same id state in every round: | | Deployed blocks | Branch, longest block | |---|---|---| | Nothing changed | 1.3-2.4 s | 0.2 s | | After polar refreshed | 1.3-2.3 s | 0.3 s | | After happy8k refreshed | 1.3-1.9 s | 0.4-0.8 s | What's left in the longest block is `assignStreams` itself, after a big provider refresh. Tests: 146/146 pass.
A deferred view rebuild blocked every request for 1.3-2.4 s on the real pool. It now runs in slices of about 25 ms, gzips on zlib's threads, and joins the category JSON for the full list instead of a second stringify. assignStreams skips the member pass for channel objects the merge reused with the same id. On the real pool the views and the id state are identical to the deployed build.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
namillis/iptv-pool!50
No description provided.