perf: release timeline memory when navigating between rooms#2949
perf: release timeline memory when navigating between rooms#2949
Conversation
- Fix timeline subscription leaks in scrollDown(), scrollToEventId() and _reloadTimelineAndWaitForRender() where timeline was set to null BEFORE cancelSubscriptions() was called, leaving 5 orphaned stream subscriptions per reload - Add _trimTimelineIfNeeded() to cap events at 500 per timeline, trimming oldest events after each requestHistory() to prevent unbounded memory growth during long scroll sessions - Clear Flutter image cache (decoded bitmaps) on ChatController.dispose() to free GPU/raster memory when leaving a room
|
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 selected for processing (1)
✨ 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/2949 |
Summary
Fix memory leaks and unbounded growth in
ChatControllerthat cause increasing memory pressure during normal navigation between rooms.Changes
timeline!.cancelSubscriptions()is now called BEFOREtimeline = nullinscrollDown(),scrollToEventId()and_reloadTimelineAndWaitForRender(). Previously, nulling the reference first left 5 orphaned stream subscriptions per timeline reload._trimTimelineIfNeeded(): Caps timeline events at 500 per room after eachrequestHistory(). Prevents unbounded memory growth during long scroll sessions. Trimmed events remain in the database and are re-fetched if the user scrolls back.dispose(): CallsPaintingBinding.instance.imageCache.clear()andclearLiveImages()when leaving a room to free decoded GPU/raster bitmaps._timestampTimerindispose().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.maintimeline-leaksRaw trace file attached:
perf-trace-timeline-leaks.json.gz(load in Chrome DevTools > Performance > Load profile to verify).Test recommendation
Ticket
No ticket — discovered during performance profiling.