Repository navigation
Auto white balance: one prop-reading akarin Expr instead of a compile per frame (#253) - #289
Merged
Merged
Conversation
…perties (issue #253) _auto_white returned a new _expr from a FrameEval on every frame, with the offsets written into the expression. _expr goes to akarin wherever it is installed (every bundle but macOS x64), so every frame was an LLVM compile in a Python callback holding the GIL: ~17 ms a frame on an M1, serial whatever the core count (the issue: 20% CPU, a 48-core EPYC slower than a desktop). With akarin, PlaneStats now stamps each chroma plane's mean on the frame and one expression, compiled once, reads it; the FrameEval stays only as the fallback without akarin, where a std.Expr per frame is cheap. The filter alone at 706x480: ~60 -> ~8,000 fps. Identical output at 8-12 bits and on the fallback; at 16 bits 0.16% of chroma planes are one step apart (akarin reads a property as a 32-bit float). Automatic levels is unchanged: a std.Levels per frame is a lookup table and cheap, and an akarin version is not bit-exact (fast-math division misses .5 ties in 2% of (min, max) pairs). A comment says so. Tests: test_271 and a Flutter script test check the akarin branch reads properties and evaluates nothing per frame; integration_auto_colour_test (heavy) checks both filters act and preview = lossless encode. CLAUDE.md: never build an akarin expression per frame, with the fast-math caveat. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ile) docs/reports/issue-253-auto-colour-per-frame-expr: the cause, the fix, the exactness probes (identical at 8-12 bits and on the fallback; 0.16% of 16-bit chroma planes one step apart), why automatic levels stays a std.Levels (akarin's fast-math division misses .5 ties in 2% of (min, max) pairs), the filter's speed (~60 -> ~8,000 fps alone) and the whole chain's (unchanged on a heavily loaded M1, explained), with every script. ENGINEERING_NOTES entry and reports index row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # docs/ENGINEERING_NOTES.md # docs/reports/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #253.
Colour Correction's automatic white balance (
_auto_white) returned a new expression from astd.FrameEvalon every frame, with the offsets written into the expression text._exprsends that to akarin wherever akarin is installed, which is every bundle except macOS x64. So each frame was an LLVM compile (~17–20 ms) in a Python callback holding the GIL, and the pass ran serially no matter how many cores the machine had. That is why the reporter's 48-core EPYC ran slower than a desktop.Change
PlaneStatscalls stamp the chroma averages on each frame as properties (_AwbU*/_AwbV*, removed afterwards), and one akarin expression reads them (x._AwbUAverage). TheFrameEvalis kept only as the fallback where akarin is absent (macOS x64), where onestd.Exprper frame costs ~0.35 ms.std.Levelsis cheap (~5,000 fps). An akarin version is not bit-exact: akarin compiles with fast-math, and its division misses .5 ties in ~2% of (min, max) pairs.docs/reports/issue-253-auto-colour-per-frame-expr, with its probes, timings and scripts. Also an ENGINEERING_NOTES entry and a row in the reports index.Testing
test_271(Rust) checks both scripts: the akarin branch reads properties and builds nothing per frame, the fallback keeps the FrameEval, and auto levels staysstd.Levels. The fullcargo testpasses.integration_filter_parameters_test.dartpasses. The push gate passed (1967 pass, 8 skipped).integration_auto_colour_test.dart: each filter changes the picture, and the preview matches the lossless encode exactly (max difference 0). Passes 2/2.🤖 Generated with Claude Code