perf: prevent iOS OOM kill with download concurrency limiter and reduced rebuilds#2950
perf: prevent iOS OOM kill with download concurrency limiter and reduced rebuilds#2950
Conversation
…ced rebuilds - Add ImageDownloadQueue (semaphore, max 4 concurrent) to throttle simultaneous image downloads and URL preview fetches - Cancel pending downloads when MxcImage is disposed (scrolled off-screen) - Integrate queue into GetPreviewUrlMixin to throttle preview_url HTTP requests - Add early-return in ChatList.didUpdateWidget and AppAdaptiveScaffoldBodyController.didUpdateWidget to skip redundant processing when args haven't changed - Bump file_picker 10.1.7 -> 10.3.10 to fix ObjC FileUtils class name collision with OSAnalytics that caused random native crashes - Add 6 unit tests for ImageDownloadQueue (FIFO, cancel, release)
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 PR has been deployed to https://linagora.github.io/twake-on-matrix/2950 |
Summary
Prevent iOS out-of-memory kills caused by unbounded concurrent image downloads when scrolling fast through rooms with many images.
Changes
ImageDownloadQueue(semaphore pattern, max 4 concurrent): Throttles simultaneous image download/decode operations. EachMxcImageacquires a slot before loading and releases it when done or disposed.MxcImageis scrolled off-screen, its download ticket is cancelled, preventing wasted work and memory allocation for images the user will never see.GetPreviewUrlMixin: Throttlespreview_urlHTTP requests through the same shared queue, preventing dozens of URL preview fetches from firing simultaneously.didUpdateWidgetearly-return inChatListandAppAdaptiveScaffoldBody: Skips redundant processing when args haven't changed, avoiding unnecessary rebuilds on every parent rebuild.file_picker10.1.7 → 10.3.10: Fixes ObjCFileUtilsclass name collision with OSAnalytics that caused random native crashes.ImageDownloadQueue(FIFO ordering, cancel, release).Performance measurements
Measured with Flutter Web
--profile, CPU throttling 4x, Chrome DevTools trace, ~75s navigation (DMs, groups 51-85 members, contacts, settings, scrolling, member lists). Fresh Chrome instance.mainimage-throttleThe primary benefit is on iOS where the OOM killer is aggressive. The web measurements confirm reduced memory pressure. On iOS, this prevents the app from being killed during fast scrolling through image-heavy rooms.
Raw trace file attached:
perf-trace-image-throttle.json.gz(load in Chrome DevTools > Performance > Load profile to verify).Test recommendation
flutter test test/utils/image_download_queue_test.dartTicket
No ticket — discovered during performance profiling.