perf: byte budget for image cache, fix video thumbnail rebuild, clear byte cache on room exit#2987
perf: byte budget for image cache, fix video thumbnail rebuild, clear byte cache on room exit#2987
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
64e8128 to
ad62574
Compare
ad62574 to
169ae12
Compare
169ae12 to
466b2a4
Compare
466b2a4 to
218e367
Compare
218e367 to
43b4200
Compare
…ed guards - MxcImageCacheManager: add 150 MB byte budget alongside the 100-entry count limit; track _totalBytes, evict LRU when over budget; reject images larger than the budget to preserve the invariant; add clear(). 150 MB covers compressed bytes (JPEG/PNG) — decoded bitmaps are handled separately by PaintingBinding.imageCache (100 MB default) - _ImageWidget: convert StatelessWidget → StatefulWidget; move generateVideoThumbnail() to initState/didUpdateWidget so it is not re-triggered on every rebuild - _tryLoad: add `if (!mounted) return` guard at entry to prevent re-entrant calls after dispose; guard setState after await with `if (mounted)`; move state mutations inside setState closures - chat.dart: call MxcImageCacheManager.instance.clear() in dispose() alongside imageCache.clear() so raw compressed bytes are also evicted when leaving a room
43b4200 to
18fabf5
Compare
There was a problem hiding this comment.
Gates Passed
3 Quality Gates Passed
See analysis details in CodeScene
Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
|
This PR has been deployed to https://linagora.github.io/twake-on-matrix/2987 |
Summary
Three targeted memory improvements following the perf audit. No functional changes — all existing behavior is preserved.
1. Byte budget for
MxcImageCacheManager(50 MB)The cache was limited to 100 entries with no size awareness. 100 images at 5 MB each = 500 MB of Dart heap. Now tracks
_totalBytesand evicts LRU entries when either the count (100) or byte budget (50 MB) is exceeded.Also adds
clear()method used by point 3 below.2. Fix video thumbnail re-generation on every rebuild
_ImageWidgetwas aStatelessWidgetwhosebuild()called:Every
setState()from a parent created a newFuture, re-runninggenerateVideoThumbnail()— which writes a temp file (mobile) or creates a blob URL (web), callsVideoThumbnail.thumbnailData(), and decodes the bitmap.Fix: convert to
StatefulWidget, compute theFutureonce ininitState()and refresh indidUpdateWidget()only whendataoreventchanges.3. Clear raw byte cache on room exit
chat.dart dispose()already calledPaintingBinding.instance.imageCache.clear()to evict decoded bitmaps. The compressed byte cache (MxcImageCacheManager) was never cleared — bytes accumulated across room navigations indefinitely. Now cleared alongside the decoded bitmap cache.Test plan
fvm flutter analyzeclean