monal-im / Monal

Monal for XMPP (iOS and macOS)
https://monal-im.org
Other
501 stars 104 forks source link

[Feature]: Improve performance when fetching a lot of history from mam #1240

Open lissine0 opened 4 days ago

lissine0 commented 4 days ago

Precondition

Cross-checked related issues?

Describe your feature

I'm using macOS (14.6.1, but it was the same on 12.x) This is not noticeable if I open Monal daily, but if I don't open it for a couple of weeks, and I have 6 active public channels, fetching mam is heavy on the CPU (uses ~125% on my old 2-core, 4-thread CPU). It makes my fan spin :D Also, the time it takes to finish seems slower than other clients. Though I did not make any precise measurements. I'm using the alpha and beta release channels, and my server is a self-hosted prosody 0.12.4

tmolitor-stud-tu commented 3 days ago

That might be because Monal uses a separate DB transaction for every incoming message stanza. Using one transaction for every incoming batch of mam stanzas (e.g. one mam page) could improve performance, but since decrypting omemo messages can sometimes take 500-1000ms, that could considerably lock up the app if applied to all catchups, not only unencrypted channels. While applying this to unencrypted channels might severly increase the complexity and decrease maintainability of our stanza handling.

There might be other parts of the app slowing down the catchup, too, that might be easier to speed up. Maybe a profiling to identify those code parts could help here.