Skip to content

unreads: Add/use locatorMap, to efficiently locate messages #1703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chrisbobbe
Copy link
Collaborator

Fixes #332.

Really the same optimization as described for zulip-mobile in
zulip/zulip-mobile#4684
, and makes mark-as-read take 0ms (to the nearest ms) down from 3 or 4, in my testing, and so fixes #332.

@chrisbobbe chrisbobbe added a-model Implementing our data model (PerAccountStore, etc.) performance Smooth and responsive UI; fixing jank, stutters, and lag maintainer review PR ready for review by Zulip maintainers labels Jul 13, 2025
Copy link
Member

@rajveermalviya rajveermalviya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chrisbobbe! LGTM, two small comments below.

DmMessage() => DmNarrow.ofMessage(message, selfUserId: selfUserId),
};
locatorMap[event.message.id] = narrow;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe merge both switches? To avoid a copy of DmNarrow and more specifically of allRecipientIds list in DmNarrow.ofMessage.

    switch (message) {
      case StreamMessage():
        final narrow = TopicNarrow.ofMessage(message);
        locatorMap[event.message.id] = narrow;
        _addLastInStreamTopic(message.id, message.streamId, message.topic);
      case DmMessage():
        final narrow = DmNarrow.ofMessage(message, selfUserId: selfUserId);
        locatorMap[event.message.id] = narrow;
        _addLastInDm(message.id, narrow);
    }

if (messageIds.isEmpty) {
newlyEmptyTopics.add(topic);
}
/// Remove any of [idsToRemove] that are in [streams].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
/// Remove any of [idsToRemove] that are in [streams].
/// Remove any of [idsToRemove] that are in [streams].

@rajveermalviya rajveermalviya removed their assignment Jul 14, 2025
@rajveermalviya rajveermalviya added integration review Added by maintainers when PR may be ready for integration and removed maintainer review PR ready for review by Zulip maintainers labels Jul 14, 2025
@rajveermalviya rajveermalviya requested a review from gnprice July 14, 2025 12:58
Fixes zulip#332.

Really the same optimization as described for zulip-mobile in
  zulip/zulip-mobile#4684
, and makes mark-as-read take 0ms (to the nearest ms) down from 3 or
4, in my testing, and so fixes zulip#332.
@chrisbobbe chrisbobbe force-pushed the pr-unreads-locator-map branch from f3988b0 to 02f9779 Compare July 14, 2025 16:01
@chrisbobbe
Copy link
Collaborator Author

Thanks for the review! Revision pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-model Implementing our data model (PerAccountStore, etc.) integration review Added by maintainers when PR may be ready for integration performance Smooth and responsive UI; fixing jank, stutters, and lag
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize unreads model on mark-as-read
3 participants