Rebuild the live event index in slices so it no longer freezes the pool #48

Merged
namillis merged 2 commits from fix/event-index-worker into main 2026-11-20 18:36:35 +00:00
Owner

After each merge the pool rebuilt the live event index (Popular on TV and Live Sports) on the main thread, and every request waited 1-3.6 s for it. With the merge now in a worker (#47), this was the last regular freeze.

The build is too tied to the channel tiles and the guide to move to a worker cheaply: copying 161k channels and the merged guide over would block about as long as the build. So the build now pauses between steps instead:

  • buildEventIndex's work is a generator that yields once per channel, guide id or event, in the steps that took more than ~20 ms on the real pool (the channel pass, guide events, replays, ESPN schedule and networks, matchup merging, TV events).
  • buildEventIndex runs it to the end in one go, as before. buildEventIndexSliced runs it in slices of about 25 ms with setImmediate in between.
  • A stale index is rebuilt with the sliced build, and requests keep getting the old index until the new one is ready. Builds never overlap. Only the first index after startup is built in one go.

On the real 15 providers (161,760 channels, 431 games, 116 shows), three runs:

Deployed This branch
Longest block 1,213-2,958 ms 47-82 ms
Rebuild time same as block 1.3-2.6 s in the background
Index 1,581 events identical (deep equal)

Tests: 144/144 pass, including a new one that the sliced build matches the one-go build and lets other work run.

After each merge the pool rebuilt the live event index (Popular on TV and Live Sports) on the main thread, and every request waited 1-3.6 s for it. With the merge now in a worker (#47), this was the last regular freeze. The build is too tied to the channel tiles and the guide to move to a worker cheaply: copying 161k channels and the merged guide over would block about as long as the build. So the build now pauses between steps instead: - `buildEventIndex`'s work is a generator that yields once per channel, guide id or event, in the steps that took more than ~20 ms on the real pool (the channel pass, guide events, replays, ESPN schedule and networks, matchup merging, TV events). - `buildEventIndex` runs it to the end in one go, as before. `buildEventIndexSliced` runs it in slices of about 25 ms with `setImmediate` in between. - A stale index is rebuilt with the sliced build, and requests keep getting the old index until the new one is ready. Builds never overlap. Only the first index after startup is built in one go. On the real 15 providers (161,760 channels, 431 games, 116 shows), three runs: | | Deployed | This branch | |---|---|---| | Longest block | 1,213-2,958 ms | 47-82 ms | | Rebuild time | same as block | 1.3-2.6 s in the background | | Index | 1,581 events | identical (deep equal) | Tests: 144/144 pass, including a new one that the sliced build matches the one-go build and lets other work run.
Rebuild the live event index in slices so it no longer freezes the pool
Some checks failed
CI / test (pull_request) Failing after 22s
9a6bdef124
The index rebuild after each merge blocked every request for 1-3.6 s. The build now yields once per channel, guide or event, and a stale index is rebuilt in slices of about 25 ms while requests keep getting the old one. Only the first index at startup is built in one go. On the real 15 providers the sliced build gives the same index as before, with no stretch over 82 ms.
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!48
No description provided.