Repository navigation
Read the zoom range once per bound camera instead of on every frame - #647
Merged
Merged
Conversation
The preview capture callback read CameraInfo.zoomState on every capture result to clamp the target zoom ratio. For a camera extension session, zoomState queries the extension's characteristics through the vendor extension service on each call. At preview frame rate this saturates the CameraX camera thread, which also completes still captures and opens and closes the camera, so captures stall and the camera takes tens of seconds to close and reopen. The zoom range doesn't change while a camera is bound, so read it once and reuse it.
Contributor
There was a problem hiding this comment.
Code Review
This pull request optimizes zoom state reading in CameraSession.kt by caching the zoomRange instead of querying it on every frame, which prevents backing up the camera thread during camera extension sessions. The feedback suggests a performance improvement to avoid unnecessary ClosedFloatingPointRange object allocations in the high-frequency preview frame path by refactoring the coerceIn logic.
davidjiagoogle
approved these changes
Nov 10, 2026
Kimblebee
approved these changes
Nov 10, 2026
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 a slow camera restart and stalled captures when a camera extension session is active (for example, Night Mode from #609).
The preview capture callback in
CameraSession.updateCameraStateWithCaptureResultsreadCameraInfo.zoomStateon every capture result to clamp the target zoom ratio. For an extension session, CameraX computeszoomStateby querying the extension's characteristics (SessionProcessor.getExtensionZoomRange→CameraExtensionCharacteristics) on each call. On the device tested, doing this at preview frame rate saturates the CameraX camera thread. That thread also completes still captures and opens and closes the camera, so work queues up behind the callbacks.The zoom range doesn't change while a camera is bound, so it is now read once per bound camera and reused. A new preview use case, and so a new callback, is created for each bound camera, so the cached range starts fresh after a lens or sub-mode change. If
zoomStateisn't available yet, it is read again on the next frame, as before.The per-frame read was added in #625.
Measurements
With Night Mode selected on a Pixel device: capture a photo, open the post-capture screen, then go back.
Testing
:core:camera:testDebugUnitTest