perf(scanner): drop two full-frame adaptive thresholds that nothing reads - #1307
Merged
bmc08gt merged 1 commit intoAug 22, 2026
Conversation
…eads
detectKikCode opened with a pair of 21x21 Gaussian adaptive thresholds into
`whitish` and `blackish`. Neither result is ever read:
- `whitish` is unconditionally overwritten a few dozen lines later by the
global `threshold(greyscale, whitish, 170, 255, THRESH_BINARY)` before
anything touches it.
- `blackish` is only read on the inverted-code path (`!check_high`), and that
path recomputes it itself, lazily, behind `blackish_created` -- with a
different algorithm (ADAPTIVE_THRESH_MEAN_C at the quality-dependent width).
So the block was two full-frame adaptive thresholds per analyzed frame, thrown
away every time. Measured on an S25 Ultra over 30 iterations per case:
1280x720 code present 10.44ms -> 4.99ms
1280x720 no code 14.30ms -> 8.90ms
1920x1080 code present 8.27ms -> 2.79ms
1920x1080 no code 10.01ms -> 4.47ms
That is ~5.5ms off every frame the analyzer processes, hit or miss -- larger
than the luminance-plane fast path it stacks on. The instrumented sweep still
decodes 18/18 and stride parity is unchanged, which is what you would expect
from deleting values nothing consumes.
iOS never carried this block.
bmc08gt
merged commit Aug 22, 2026
464b2c9
into
fix/scanner-badge-dot-candidate-prune
3 checks passed
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.
detectKikCodeopened with a pair of full-frame 21×21 Gaussian adaptive thresholds:Neither result is ever read.
whitishis unconditionally overwritten before anything touches it, by the globalthreshold(greyscale, whitish, 170, 255, THRESH_BINARY)a few dozen lines down.blackishis only read on the inverted-code path (!check_high), and that path recomputes it itself, lazily, behindblackish_created— with a different algorithm (ADAPTIVE_THRESH_MEAN_C, at the quality-dependent width rather than a hardcoded 21).So every analyzed frame paid for two full-frame adaptive thresholds whose output was discarded.
Cost, measured
S25 Ultra, 30 iterations per case, native detect only (no plane conversion), through the real render path:
~5.5 ms off every frame, hit or miss — the "no code" rows are the ones that matter most, since that is what the analyzer pays while the user is still lining the phone up. This is larger than the luminance-plane fast path it stacks on top of.
The instrumented sweep still decodes 18/18 and stride parity is unchanged, which is what deleting values nothing consumes should look like.
iOS never carried this block.
Stacked on #1306.