forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unread: Convert unread.streams to Immutable!
This makes us quite a bit faster at handling a message being marked as read! That's a frequent and latency-sensitive path -- whenever the user is reading a conversation and sees some messages that were unread, this is part of the path to updating the "N unreads" banner at the top of their view. Measurements described below. As we convert the other parts of the unread state, we'll want to fold their reducers into this file too, and in fact combine the logic. No need to have four copies of all this, most of which is the same. While making this conversion, I notice that this reducer doesn't reset state on LOGIN_SUCCESS like it does for LOGOUT and ACCOUNT_SWITCH. In general we're pretty consistent about resetting state on those latter two, but many of our reducers do so on LOGIN_SUCCESS while many others don't. I've filed zulip#4446 for fixing them all up to be consistent. Performance measurements: I made some manual performance measurements to evaluate this change and the others in this series. I used a test user with lots of unreads on chat.zulip.org, on a few-years-old flagship phone: a Pixel 2 XL running Android 10. The test user has 50k unreads in this data structure (that's the max the server will send in the initial fetch), across about 3400 topics in 27 different streams. Before this series, on visiting a topic with 1 unread, we'd spend about 70ms in this reducer, which is a long time. We'd spend 300ms in total on dispatching the EVENT_UPDATE_MESSAGE_FLAGS action, including the time spent in the reducer. (The other time is probably some combination of React re-rendering the components that use this data; before that, our selectors that sit between those components and this data recomputing their own results; and after that, React Native applying the resulting updates to the underlying native components. We don't yet have clear measurements to tell how much time those each contribute.) After this change, we spend about 30-50ms in the reducer, and a total of 150-200ms in dispatch. Still slow, but much improved! We'll speed this up further in upcoming commits. For EVENT_NEW_MESSAGE, which is the other frequent update to this data structure, not much changes: it was already "only" 4-9ms spent in this reducer, which is too slow but far from our worst performance problem. After this change, it's usually <=1ms (too small to measure with our existing tools), and the longest I've seen is 3ms. The total dispatch time varies widely, like 70-200ms, and it's not clear if it changed. There is one performance regression: we now spend about 100ms here on REALM_INIT, i.e. on handling the data from the initial fetch. Previously that time was <=1ms; we just took the data straight off the wire (well, the data we'd already deserialized from the JSON that came off the wire), and now we have to copy it into our more efficiently-usable data structure. As is, that 100ms is already well worth it: we save more than 100ms, of visible latency, every time the user reads some unread messages. But it's enough to be worth optimizing too, and we'll do so later in this series. Fixes-partly: zulip#4438
- Loading branch information
Showing
6 changed files
with
170 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.