Repository navigation
Reduce coupon barcode CPU while preserving recognition - #533
Merged
Merged
Conversation
Szer
enabled auto-merge (squash)
September 28, 2026 11:23
Szer
disabled auto-merge
September 28, 2026 11:30
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.
Difficult coupon photos spend seconds in the synchronous barcode search before reaching text OCR. Run ZXing-C++ on grayscale pixels and cropped views first, then retain the managed recovery search with reusable luminance buffers and redundant inversion disabled. Native library failures safely use the managed fallback. Native views use bounded spans and a scoped managed pin lease, with no unsafe code or raw pointers in the adapter.
A paired CPU-only benchmark over all 2,201 downloaded coupon images reduces total CPU by 47.8%, and CPU for the 20 control no-reads by 47.2%. Overall p99 elapsed parsing falls from 2.53 s to 0.66 s. A throttled ARM64 container using the production runtime base reduces one difficult image from 28.9 s / 7.23 CPU s to 14.7 s / 3.67 CPU s.
No previously correct result is lost. All 421 holdout outputs are unchanged. Labels include reviewed disagreements and approved OCR consensus for missing values; this positive-only corpus cannot establish a true-negative rate. Private images, labels and benchmark observations stay outside the repository.
Validation: 264 integration tests and 26 OCR/behavior tests pass without paid OCR calls; ARM64 native dependencies and missing-library fallback are exercised separately. New tests assert barcode recognition at four orientations and no invented barcode on blank images.
A separate binding-only upgrade check (ImageSharp binding 0.16.18 → 0.16.20, same ZXing.Net 0.16.11 core) produces identical results on all 2,201 images and effectively identical CPU totals (112.55 s versus 112.45 s). The checked-span adapter preserves all corpus outputs and passes 64 repeated decodes during 14,095 compacting garbage collections.
On 2,144 control first-attempt successes, a balanced three-repeat comparison isolates the native-stage cost: happy-path p95 falls from 9.35 ms (optimized managed only) to 8.43 ms (native + managed fallback), with median latency 4.41 ms → 3.81 ms. Three individual images add 12–19 ms because of native crops/fallback. These are local CPU-only measurements; ARM64 happy-path p95 is not established by the single-image ARM spot check.
The snapshot race-test harness runs parked loads on workers, bounds its gates and releases them on concurrent-operation failure. This prevents synchronous database completion from blocking the test before it can release the parked fold. A deterministic scheduling repro and all 34 BotInfra tests pass locally and on ARM64 CI. All PR checks pass; the Vahter job completes in 5m52s.