Skip to content

perf(producer): gate per-frame debug meta via optional isLevelEnabled#383

Open
vanceingalls wants to merge 1 commit intovance/hdr-benchmark-harnessfrom
vance/logger-level-gating
Open

perf(producer): gate per-frame debug meta via optional isLevelEnabled#383
vanceingalls wants to merge 1 commit intovance/hdr-benchmark-harnessfrom
vance/logger-level-gating

Conversation

@vanceingalls
Copy link
Copy Markdown
Collaborator

@vanceingalls vanceingalls commented Apr 21, 2026

Summary

Add an optional isLevelEnabled(level) method to ProducerLogger and use it to short-circuit per-frame HDR composite metadata construction in renderOrchestrator when the log level is above debug.

Closes Chunks 8C and 8D from plans/hdr-followups.md.

Why

Chunk 8C of plans/hdr-followups.md. The per-frame HDR composite snapshot (every 30 frames) was building an Array.find + toFixed + struct allocation unconditionally and handing it to a debug logger that immediately discarded it at level="info". On long renders, this is allocation pressure and CPU time wasted on log meta nobody reads.

Chunk 8D was investigated in the same pass and found to already be guarded — see below.

What changed

  • New optional isLevelEnabled(level: ProducerLogLevel): boolean on ProducerLogger.
  • createConsoleLogger implements it.
  • renderOrchestrator.ts per-frame HDR composite snapshot is now gated on i % 30 === 0 && (log.isLevelEnabled?.("debug") ?? true) — production runs at level="info" skip the meta-object construction entirely; custom loggers without the new method keep their existing behavior thanks to the ?? true fallback.
  • New packages/producer/src/logger.test.ts (17 tests) covering level filtering, meta formatting, the isLevelEnabled path, a hot-loop call-site simulation that asserts zero builder invocations at info level, and the ?? true fallback for loggers that omit the method.
  • docs/packages/producer.mdx gains a new "Logging" section documenting ProducerLogger, createConsoleLogger, defaultLogger, and the isLevelEnabled gating pattern.

8D resolution (no code change). countNonZeroAlpha / countNonZeroRgb48 calls live behind shouldLog = debugDumpEnabled && debugFrameIndex >= 0, where debugDumpEnabled is itself driven by KEEP_TEMP=1. The pixel iteration is fully skipped on production runs already, so 8D needed no fix — verified during the 8C work.

Test plan

  • bun test in producer — 17/17 logger tests pass; existing service tests unchanged.
  • Hot-loop call-site simulation asserts the meta builder is invoked zero times at level="info".
  • ?? true fallback preserves prior behavior for custom logger implementations that don't define the method.
  • Re-ran the HDR benchmark from Chunk 8A — no regression on wall-clock, peak heap unchanged at info level.

Stack

Chunks 8C + 8D of plans/hdr-followups.md. Sits on top of the benchmark harness PR (Chunk 8A) so the optimization is measurable.

Copy link
Copy Markdown
Collaborator Author

vanceingalls commented Apr 21, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from a4873ca to 35fee67 Compare April 22, 2026 18:50
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from 8d9641b to 3fcaa60 Compare April 22, 2026 18:59
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 35fee67 to 2159cf0 Compare April 22, 2026 18:59
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from 3fcaa60 to e675bd9 Compare April 22, 2026 19:34
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 2159cf0 to d746856 Compare April 22, 2026 19:34
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from e675bd9 to f73328c Compare April 22, 2026 20:45
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 2217a93 to 8610f7e Compare April 22, 2026 20:48
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from f73328c to 55a41a8 Compare April 22, 2026 20:48
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 8610f7e to 0d2175b Compare April 22, 2026 22:13
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from 55a41a8 to 349f0f6 Compare April 22, 2026 22:13
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 0d2175b to cd40e4b Compare April 22, 2026 22:53
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from 349f0f6 to cd65ab0 Compare April 22, 2026 22:54
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from cd40e4b to 5594d94 Compare April 22, 2026 23:26
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from cd65ab0 to 5409b1a Compare April 22, 2026 23:26
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 5594d94 to 4ea0021 Compare April 23, 2026 00:06
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from 5409b1a to c6a8280 Compare April 23, 2026 00:07
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 4ea0021 to c95ffe5 Compare April 23, 2026 00:11
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch 2 times, most recently from 2ce89a5 to b8d319d Compare April 23, 2026 00:45
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from c95ffe5 to 6cf7b33 Compare April 23, 2026 00:45
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from b8d319d to d222b31 Compare April 23, 2026 01:58
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 23df022 to 53e0f64 Compare April 23, 2026 02:59
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from d222b31 to e72f484 Compare April 23, 2026 02:59
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 53e0f64 to 9d3aa62 Compare April 23, 2026 03:22
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from e72f484 to 5338173 Compare April 23, 2026 03:22
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 9d3aa62 to 3500be4 Compare April 23, 2026 03:43
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from 5338173 to b99006d Compare April 23, 2026 03:44
@vanceingalls vanceingalls force-pushed the vance/hdr-benchmark-harness branch from 3500be4 to f572ea8 Compare April 23, 2026 04:52
Add an optional `isLevelEnabled(level)` method to `ProducerLogger` so call
sites can short-circuit expensive metadata construction in hot loops
before handing it to a debug logger. Implement it in
`createConsoleLogger` and gate the per-frame HDR composite snapshot in
`renderOrchestrator` (every 30 frames) on
`log.isLevelEnabled?.("debug") ?? true`, so production runs at
`level="info"` skip the `Array.find` + `toFixed` + struct allocation
entirely while custom loggers without the new method keep their
existing behavior.

Also add unit coverage in `packages/producer/src/logger.test.ts` (17
tests) for level filtering, meta formatting, the new `isLevelEnabled`
path including a hot-loop call-site simulation that asserts zero
builder invocations at info level, and the `?? true` fallback for
loggers that omit the method.

Update `docs/packages/producer.mdx` with a new "Logging" section
documenting `ProducerLogger`, `createConsoleLogger`, `defaultLogger`,
and the `isLevelEnabled` gating pattern.

This closes 8C in `plans/hdr-followups.md`. 8D (gating the
`countNonZeroAlpha` / `countNonZeroRgb48` diagnostic counters) was
verified during the same work to already be guarded by
`shouldLog = debugDumpEnabled && debugFrameIndex >= 0`, where
`debugDumpEnabled` is itself driven by `KEEP_TEMP=1`, so the pixel
iteration is fully skipped on production runs and no code change was
needed.

Made-with: Cursor
@vanceingalls vanceingalls force-pushed the vance/logger-level-gating branch from b99006d to 644607f Compare April 23, 2026 04:52
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.

2 participants