deltachat / deltachat-core-rust

Delta Chat Rust Core library, used by Android/iOS/desktop apps, bindings and bots 📧
https://delta.chat/en/contribute
Other
659 stars 85 forks source link

Only load Chat and Contact once in receive_imf #3779

Open Hocuri opened 1 year ago

Hocuri commented 1 year ago

receive_imf could have some easy speed wins:

Currently, it always passes around a chat_id and contact_id, and then loads them from the database repeatedly. Instead, they should be loaded only once, and then the struct should be passed around. As a bonus, this should also make the code a bit simpler.

This will create quite a diff though because the chat_id and contact_id are used in so many places. So,

  1. it's nothing that can be done in an hour or so
  2. it should be done for Chat and Contact in two PRs, not one big PR that tries to do both at once.

When I measured it quite a while ago, this were the results I saw in the flamegraph for a rather simple message (e.g. 20% of the time in receive_imf is spent on Chat::load_from_db()):

Probably it would be more precise to build in timing logs into the code and then measuring on a real device.

link2xt commented 1 year ago

Loading from_id only once is likely the easiest. With chat_id I have not checked, but generally assignment of messages to chats is complicated by itself, so this could be a next step.