Repository navigation
Commit 4222971
perf(producer): parallelize transition-frame phase across worker DOM sessions
The prior hf#732 hybrid path kept transition frames pinned to the main DOM
session while only parallelizing the cheaper normal-frame portion. perf-
summary.json showed transitionCompositeMs summed to 109,838ms over 141
frames (avg 779ms) on a 175,973ms total capture, so the sequential
transition phase was structurally upper-bound at ~110s of the 171s wall.
This fix removes that structural cap. Every worker now walks a contiguous
slice of the full frame range and runs both normal-frame and transition-
frame compositing against its own browser session — processLayeredTransition
Frame is self-contained per call (the dual-scene seek/mask/screenshot/
blend pattern only requires the same window.__hf state across the two
scenes within ONE call), so there's no inter-frame dependency that would
tie transitions to a specific session. Per-worker scratch buffers
(bufferA/bufferB/output, 3 × width*height*6 bytes each) are allocated up
front. The FrameReorderBuffer already supports arbitrary completion
order, so encoder writes still hit the muxer in ascending index order.
The new distributeLayeredHybridFrameRanges helper is exported so the
partitioning contract is unit-testable. Five new tests pin:
- non-overlapping, contiguous, full-coverage worker slices
- the hf#732 transition shape (14 × 10-frame transitions on 840 frames)
spreads transition work across multiple workers instead of pinning it
all to worker 0
- the workerCount=0 / totalFrames=0 / workers > frames edge cases
Empirical results on the SDR shader-transition repro (15 scenes × ~2s,
854×480, 14 × 0.3s shader transitions) match the structural change but
do NOT close the predicted 5× gap. Wall times (current VM, w=6, 2 trials
per cell, baseline collected on the same machine in the same session):
Cell | BEFORE (hf#732) | AFTER | Speedup
shader auto | 220s / 221s | 184s | ~1.18×
shader w=6 explicit | 209s / 183s | 184s | ~1.07×
hardcut auto | 9s / 10s | 9-10s | ~1.0×
hardcut w=6 | 8s / 9s | 8-9s | ~1.0×
The structural fix is correct — perf-summary.json shows transitions now
run concurrently across workers (avg transitionCompositeMs climbs from
779ms to 882ms per frame due to expected cross-worker contention, with
total work summed across all 6 workers). But the wall clock does not
collapse to ~30s as predicted, because the actual bottleneck is NOT
DOM-session serialization — it's the JS shader-blend in
TRANSITIONS[shader](...) running on the Node main thread. Complex
shaders like domain-warp, swirl-vortex, glitch iterate every pixel
in JS with multiple noise/sample calls per pixel; for 854×480 that's
hundreds of milliseconds per call on the main event loop. Six workers
all firing shader-blends saturate the single Node thread, so observable
parallelism caps at ~1.2× regardless of worker count (verified on this
fixture: w=1=218s, w=2=183s, w=6=184s, w=12=188s — the curve flattens
after w=2, consistent with a single-threaded JS bottleneck downstream
of the worker pool).
Follow-up to actually close the 5× gap is a separate change: move the
shader-blend (TRANSITIONS[shader](...)) onto worker_threads so the
per-pixel JS doesn't serialize on the orchestrator's event loop. The
rgb48le scratch buffers are well-suited to zero-copy transfer via
transferList. That refactor is out of scope for the hf#732 fix-up.
— Vai
Co-Authored-By: Vai <[email protected]>1 parent cc80f91 commit 4222971
2 files changed
Lines changed: 234 additions & 101 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
718 | 719 | | |
719 | 720 | | |
720 | 721 | | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
721 | 801 | | |
722 | 802 | | |
723 | 803 | | |
| |||
0 commit comments