zulip-flutter
zulip-flutter copied to clipboard
Optimize unreads model on mark-as-read
In #304 we implemented the Unreads
model, and measured that its performance was quite fast for most operations, but not for marking messages as read. The timings are in the series of messages starting at https://github.com/zulip/zulip-flutter/pull/304#issuecomment-1775980154 .
In particular, in those experiments it took 0ms (to the nearest ms) to construct the whole model in the first place, as well as most other operations. But it took about 14ms for a mark-as-read event, whether for marking one or many individual messages as read.
As I said at https://github.com/zulip/zulip-flutter/pull/304#issuecomment-1776034014 :
Given how very fast the constructor is in particular, I feel like it should be possible to get mark-as-read to be much faster — in particular I think it fundamentally shouldn't be any slower than the constructor. And taking 14ms is enough that it'll often cause a dropped frame, so that's worth avoiding.
The first step here is probably to profile to see specifically where the time is being spent, e.g. to get a flame chart: https://docs.flutter.dev/tools/devtools/cpu-profiler#flame-chart
(My original suggestion at https://github.com/zulip/zulip-flutter/pull/304#discussion_r1339386508 didn't seem to help, or not much. That was without the benefit of profiling.)
Given that the existing code is already much faster at constructing the whole model from scratch than it is at handling mark-as-read, I'm expecting that there'll turn out to be a way to make this much faster without needing the deeper data-structure changes described at zulip/zulip-mobile#4684 . If we do need the latter (or do eventually pursue those too, for the sake of going even faster), then that will be a post-launch task.