Fix live scanner freezing/stutter and clean up detection overlay (iOS + Android) - #1
Merged
Merged
Conversation
… + Android) Several issues in the live camera scanner, across both platforms. iOS — preview froze for seconds at a time (CameraScanner.ios.kt): - Root cause: CoreML inference ran on the GPU (the model has NMS baked in, which keeps it off the Neural Engine), contending with the GPU-bound camera preview compositing. Force inference onto the Neural Engine + CPU (computeUnits = cpuAndNeuralEngine) so the GPU is free for the preview. - Call onResult directly from the inference queue instead of dispatching a Kotlin lambda to the GCD main queue every frame, which had been accumulating GC roots and triggering stop-the-world pauses. - Load the Vision request off the main thread; use an atomic busy flag and cache the request list / options map to avoid per-frame allocations. - Raise inference rate to ~10/sec now that it no longer stalls the preview, and bump the preview preset to 720p (with fallback). - Raise the Kotlin/Native GC target heap (build.gradle.kts) so it pauses the app less often under the camera + ML workload. Shared UI — boxes jumped and the fps chip was broken (ScanScreen.kt): - Interpolate detection boxes at display refresh rate so they glide after the clover instead of jumping between inference updates. (both platforms) - Mark CloverDetector @stable and memoize the frame callback so state updates don't force the CameraScanner (and its UIKitView) to recompose. (both) - Fix the fps chip showing a literal "%d fps" by formatting in Kotlin; drop the now-unused fps_format string resource. (both) Android (CloverDetector.android.kt, CameraScanner.android.kt): - Skip the JPEG encode/decode round-trip by passing the camera Bitmap straight into ONNX inference.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
Fixes several issues in the live clover scanner across both iOS and Android. The main fix is the iOS camera preview freezing for seconds at a time during detection; along the way this also cleans up shared-UI issues (box tracking, fps display) and an Android optimization.
Problems
Root cause (iOS freeze)
The CoreML model has NMS baked in (nms=True), which keeps it off the Neural Engine and runs inference on the GPU. That contended with the GPU-bound camera preview compositing, so every inference stalled the preview.
Changes
iOS — preview freeze (CameraScanner.ios.kt)
Shared UI (ScanScreen.kt)
Android (CloverDetector.android.kt, CameraScanner.android.kt)