Repository navigation
Commit 75aa2d8
perf(producer): hybrid layered/parallel path for SDR shader-transition renders
hf#732 PR 4 of 5. Delivers the bulk of the 2.22x shader-transition
speedup by spreading per-frame DOM capture work across N DOM worker
sessions and offloading the per-pixel shader-blend onto a
`worker_threads` pool (the pool added in PR 3).
The hybrid path is gated by `shouldUseHybridLayeredPath`:
* SDR content only (HDR raw-frame sources are fd-bound to one worker;
per-worker `dup(fd)` is out of scope here).
* workerCount >= 2.
* Not every frame inside a transition window (parallel workers buy
nothing for all-transition compositions).
When the gate trips, the hybrid loop spawns `workerCount - 1` extra
DOM sessions in addition to the existing `domSession`, allocates per-
worker scratch buffers, and partitions the frame range into contiguous
slices via `distributeLayeredHybridFrameRanges`. Each worker walks its
slice; the shader-blend at the tail of each transition frame is
dispatched to the worker pool (with inline fallback when the pool
spawn fails). `createFrameReorderBuffer` fences the encoder so out-of-
order worker completions hit the muxer in ascending frame-index order.
Pool teardown is guaranteed via try/finally on both the success and
error paths. The DOM worker sessions and the shader-blend pool both
close even when the inner loop throws.
Structural change (necessary for the perf change):
`captureHdrStage.ts` was 921 lines on main, the inner per-frame loop
was 250+ lines, and the file already exceeded the project's 500-line
ceiling. Adding the hybrid path on top would push it past 1100 lines
and the local pre-commit hook refuses to stage files past 500.
Splitting `captureHdrStage.ts` into:
* `captureHdrStage.ts` (orchestrator + cleanup invariants)
* `captureHdrResources.ts` (HDR video extraction + image decode + dim probing)
* `captureHdrFrameShared.ts` (gating predicates, partitioning,
per-scene capture primitives shared by both loops)
* `captureHdrSequentialLoop.ts` (legacy single-session loop)
* `captureHdrHybridLoop.ts` (new multi-worker SDR path)
is the simplest way to land the perf change while honoring the
project's file-size rule. No behavior change in any pre-existing code
path: the sequential loop is byte-equivalent to the previous inline
implementation (both consume `captureSceneIntoBuffer` from the shared
module, so behavior parity is enforced structurally).
`renderOrchestrator.ts` is unchanged. The stage computes its own
worker budget via `calculateOptimalWorkers` rather than receiving it
through the call signature.
Tests:
* `captureHdrFrameShared.test.ts` -- 14 vitest tests pinning the hybrid
gating predicate (SDR/HDR, all-transition edge, worker budget) and
the contiguous-chunking partitioner. All pass.
* Producer typecheck clean; oxlint clean.
PR 4 of 5 in the hf#732 decomposition stack; stacked on top of PR 3
(shaderTransitionWorkerPool).
-- Vai
Co-Authored-By: Vai <vai@heygen.com>1 parent 30348af commit 75aa2d8
7 files changed
Lines changed: 1517 additions & 603 deletions
File tree
- packages
- cli/src
- producer/src/services/render/stages
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
3 | 33 | | |
4 | 34 | | |
5 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
0 commit comments