Skip to content

refactor(producer): simplify — extract HDR compositor, delete dead code, consolidate patterns#1414

Merged
miguel-heygen merged 8 commits into
mainfrom
refactor/producer-simplification
Jun 13, 2026
Merged

refactor(producer): simplify — extract HDR compositor, delete dead code, consolidate patterns#1414
miguel-heygen merged 8 commits into
mainfrom
refactor/producer-simplification

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

Summary

  • Extract ~700 LOC of HDR compositing code from the 2,474-LOC renderOrchestrator.ts god module into a focused hdrCompositor.ts module
  • Delete 4 re-export shim files that existed solely to forward symbols from @hyperframes/engine (47 LOC)
  • Delete the unused PNG decode/blit worker pool — never wired into any capture path (~997 LOC including CLI references)
  • Centralize frame filename construction into two shared helpers, replacing 4 inline padStart(6) sites
  • Consolidate the repeated timingStart = Date.now(); ...; addHdrTiming() timing pattern into timeHdrPhase/timeHdrPhaseAsync wrappers
  • Hoist per-frame allElementIds allocation out of the per-layer compositing loop
  • Remove as Buffer typecasts, deduplicate seek+inject+query stacking pattern across 3 HDR capture files
  • Name magic numbers (TRANSFORM_IDENTITY_EPSILON, OPAQUE_ALPHA_THRESHOLD, RGB48_BYTES_PER_PIXEL), add typed AffineMatrix tuple to eliminate non-null assertions, extract resolveBlitOpacity helper

Net result: -957 LOC across 26 files. renderOrchestrator.ts reduced from 2,474 to 1,767 LOC. Zero behavior changes — pure structural refactor verified by typecheck + build + fallow audit.

Test plan

  • bun run --cwd packages/producer typecheck passes
  • bun run build passes (including CLI bundle without deleted worker entry point)
  • bunx oxlint and bunx oxfmt --check pass on all changed files
  • fallow audit: 0 new issues in 27 changed files
  • CI: unit tests pass
  • CI: regression test baselines unchanged

Move ~700 LOC of HDR compositing primitives (countNonZeroAlpha,
countNonZeroRgb48, cropRgb48le, HdrVideoFrameSource,
closeHdrVideoFrameSource, blitHdrVideoLayer, HdrImageBuffer,
blitHdrImageLayer, CompositeTransfer, shouldUseLayeredComposite,
resolveCompositeTransfer, HdrCompositeContext, compositeHdrFrame,
HdrTransitionMeta, TransitionRange) into a dedicated
hdrCompositor.ts module.

Remove backward-compat re-exports from renderOrchestrator (hdrPerf,
captureCost, shared) and rewire all import sites to the
authoritative source modules.
screenshotService.ts, videoFrameExtractor.ts, videoFrameInjector.ts,
and streamingEncoder.ts existed solely to re-export symbols from
@hyperframes/engine. No internal consumer imported from them except
index.ts → videoFrameInjector, which now imports directly from engine.
The pool (455 LOC) and worker (127 LOC) were built speculatively for
pipelining Chrome screenshots with PNG decode/blit but were never
wired into any capture path. Zero non-test source files imported them.

Also removed the esbuild entry point from producer/build.mjs, the
tsup entry point + alpha-blit alias from cli/tsup.config.ts, and
the PNG worker bootstrap from cli/src/cli.ts.
Replace 4 inline padStart(6) template literals with shared helpers:
- formatCaptureFrameName(index, ext): zero-based, for internal capture
- formatExportFrameName(index, ext): zero-based input, one-based output
  for user-facing png-sequence export
Move fullStacking.map() from inside the per-layer iteration to before
the loop, computing the element ID list once per frame instead of once
per DOM layer per frame.
…erns

- Extract seekInjectAndQueryStacking() and seekAndInject() helpers to
  deduplicate the seek+inject+query pattern across sequential loop,
  hybrid loop, and per-scene transition capture (3 call sites → 1 helper)
- Fix sceneBuf as Buffer casts by properly typing the scene-capture
  arrays as [Buffer, Set<string>][] instead of using as const + cast
- Replace as NonNullable<> cast on outputFormat with as const fallback
- Add explanatory comments on inherent linkedom DOM casts
- Replace magic 0.001/0.999 with TRANSFORM_IDENTITY_EPSILON and
  OPAQUE_ALPHA_THRESHOLD; replace BPP=6 with RGB48_BYTES_PER_PIXEL
- Add AffineMatrix tuple type + isAffineMatrix guard, eliminating
  all 4 non-null assertions on matrix indices
- Extract resolveBlitOpacity() to replace 5 identical ternaries
- Narrow fallow-ignore-file to line-level complexity suppressions
@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Splitting into a Graphite stack of smaller PRs for easier review.

@miguel-heygen miguel-heygen reopened this Jun 13, 2026
@miguel-heygen miguel-heygen merged commit a0d7295 into main Jun 13, 2026
84 checks passed
@miguel-heygen miguel-heygen deleted the refactor/producer-simplification branch June 13, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant