mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-14 18:01:20 +08:00
4279ba20e5
hf#677 follow-up. Adds a `worker_threads`-based pool that runs the shader-transition blend (one of 15 transition shaders) on a fixed-size worker pool. No production wiring yet — the pool stands alone and the hybrid path in PR 4 wires it up. Why a separate pool: the shader blend is a hot inner loop iterated over every pixel of every transition frame at 16bpc. Running it on the main event loop was previously the dominant wall-time bottleneck once DOM capture parallelism was reached. Moving it to `worker_threads` unblocks the main thread for CDP dispatch and pipelined decode/blit. Pieces: * `shaderTransitionWorker.ts` — the worker entry. Imports `TRANSITIONS` + `crossfade` from `@hyperframes/engine/shader-transitions` (the subpath added here on the engine package). Like the alpha-blit subpath, this is a zero-import TS file so it survives the `new Worker(<path>)` loader boundary without dragging in the producer module graph. * `shaderTransitionWorkerPool.ts` — fixed-size pool with `run()` API. Uses `transferList` so the 16bpc HDR `from`/`to`/`out` buffers move by ownership across the boundary instead of being copied. * `shaderTransitionWorkerPool.test.ts` — 6 vitest tests pinning byte- equivalence across all 15 shaders against an inline reference, transferList correctness, and pool lifecycle (concurrent dispatch + termination). All pass. Build wiring: * `packages/cli/tsup.config.ts`: third tsup entry emits `dist/shaderTransitionWorker.js` alongside `dist/cli.js`. Same rationale as the pngDecodeBlitWorker entry in PR 2 — the pool's `new Worker(<path>)` resolver probes for that file next to its loaded module. * `packages/producer/build.mjs`: fourth esbuild entry emits the worker as `dist/services/shaderTransitionWorker.js` for direct producer consumers. Adds the `@hyperframes/engine/shader-transitions` workspace alias to the existing `workspaceAliasPlugin`. * `packages/engine/package.json`: adds `./shader-transitions` subpath export pointing at `src/utils/shaderTransitions.ts`. The file is already import-free so the worker can consume the TS source directly. No behavior change in any render. PR 3 of 5 in the hf#732 decomposition stack; stacked on top of PR 2 (pngDecodeBlit pool). -- Vai Co-Authored-By: Vai <vai@heygen.com>
1002 B
1002 B