File: lib/services/offline_service.dart
Line: ~53-61 (in downloadToDevice -> onReceiveProgress)
Description:
The downloadToDevice() method hooks Hive.box.put() synchronously onto the Dio onReceiveProgress callback:
onReceiveProgress: (received, total) {
if (total > 0) {
_box.put(videoId, {...});
}
}
Since the progress callback is called extremely frequently (hundreds of times per second for fast network streams), it hammers the device's storage layer with disk write operations, causing severe lag and frame drops during downloads.
Impact:
Severe UI stuttering, frame drops, and unnecessary wear on device flash storage.
Suggested Fix:
Throttle the progress writes. Since downloadProgressProvider already handles realtime UI progress via WebSocket events, this disk state should only be updated periodically (e.g. every 500ms or 1MB written):
int lastUpdate = DateTime.now().millisecondsSinceEpoch;
onReceiveProgress: (received, total) {
int now = DateTime.now().millisecondsSinceEpoch;
if (now - lastUpdate > 500 || received == total) {
lastUpdate = now;
_box.put(videoId, ...);
}
}
File:
lib/services/offline_service.dartLine: ~53-61 (in
downloadToDevice->onReceiveProgress)Description:
The
downloadToDevice()method hooksHive.box.put()synchronously onto the DioonReceiveProgresscallback:Since the progress callback is called extremely frequently (hundreds of times per second for fast network streams), it hammers the device's storage layer with disk write operations, causing severe lag and frame drops during downloads.
Impact:
Severe UI stuttering, frame drops, and unnecessary wear on device flash storage.
Suggested Fix:
Throttle the progress writes. Since
downloadProgressProvideralready handles realtime UI progress via WebSocket events, this disk state should only be updated periodically (e.g. every 500ms or 1MB written):