perf(android): move thumbnail encoding off UI path

This commit is contained in:
Codex
2026-08-10 17:59:42 +02:00
parent 4a5a01dc97
commit 03227320f4
3 changed files with 102 additions and 31 deletions
@@ -111,8 +111,16 @@ class _BrowserViewState extends ConsumerState<BrowserView>
static const _pointerThrottleInterval = Duration(milliseconds: 32);
DateTime _lastPointerEvent = DateTime(0);
Offset _accumulatedDelta = Offset.zero;
bool _screenshotCaptureInFlight = false;
Future<void> _timerTick(Timer timer) async {
// Timer.periodic does not await async callbacks. A slow Gecko capture used
// to overlap the next tick, multiplying GPU readbacks, bitmap encoders and
// thumbnail events exactly while the device was already under load.
if (_screenshotCaptureInFlight) {
return;
}
// Skip the (expensive) Gecko render-to-bitmap while a full-cover route
// (settings, tab tray, search, …) occludes the browser. The screenshot
// would force an off-screen render the user can't see and competes for the
@@ -133,15 +141,17 @@ class _BrowserViewState extends ConsumerState<BrowserView>
return;
}
await ref
.read(selectedTabSessionProvider)
.requestScreenshot(requireImageResult: false)
.onError((error, stackTrace) {
logger.e(error, stackTrace: stackTrace);
timer.cancel();
return null;
});
_screenshotCaptureInFlight = true;
try {
await ref
.read(selectedTabSessionProvider)
.requestScreenshot(requireImageResult: false);
} catch (error, stackTrace) {
logger.e(error, stackTrace: stackTrace);
timer.cancel();
} finally {
_screenshotCaptureInFlight = false;
}
}
@override