From 5e1c41dc02b020a7b718ff2350e7fc905f3af7f9 Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Tue, 6 Sep 2022 14:54:04 -0400 Subject: [PATCH] Remove `renderMessages` & revert msg limit to 5k The separate list for render messages seems to have little effect for performance, so removing it. There has been some odd performance side effects with having a 10k message limit, so I've reverted that as well. --- lib/screens/channel/chat/chat.dart | 4 ++-- lib/screens/channel/chat/stores/chat_store.dart | 17 +---------------- .../channel/chat/stores/chat_store.g.dart | 11 +---------- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/lib/screens/channel/chat/chat.dart b/lib/screens/channel/chat/chat.dart index efc4275b..b97a0161 100644 --- a/lib/screens/channel/chat/chat.dart +++ b/lib/screens/channel/chat/chat.dart @@ -42,9 +42,9 @@ class Chat extends StatelessWidget { padding: EdgeInsets.zero, addAutomaticKeepAlives: false, controller: chatStore.scrollController, - itemCount: chatStore.renderMessages.length, + itemCount: chatStore.messages.length, itemBuilder: (context, index) => ChatMessage( - ircMessage: chatStore.renderMessages.reversed.toList()[index], + ircMessage: chatStore.messages.reversed.toList()[index], chatStore: chatStore, ), ); diff --git a/lib/screens/channel/chat/stores/chat_store.dart b/lib/screens/channel/chat/stores/chat_store.dart index c68e240e..93506f85 100644 --- a/lib/screens/channel/chat/stores/chat_store.dart +++ b/lib/screens/channel/chat/stores/chat_store.dart @@ -20,10 +20,7 @@ class ChatStore = ChatStoreBase with _$ChatStore; abstract class ChatStoreBase with Store { /// The total maximum amount of messages in chat. - static const _messageLimit = 10000; - - /// The maximum ammount of messages to render when autoscroll is enabled. - static const _renderMessageLimit = 100; + static const _messageLimit = 5000; /// The amount of messages to free (remove) when the [_messageLimit] is reached. final _messagesToRemove = (_messageLimit * 0.2).toInt(); @@ -94,18 +91,6 @@ abstract class ChatStoreBase with Store { @readonly var _messages = ObservableList(); - @computed - List get renderMessages { - // If autoscroll is disabled, render ALL messages in chat. - // The second condition is to prevent an out of index error with sublist. - if (!_autoScroll || _messages.length < _renderMessageLimit) return _messages; - - // When autoscroll is enabled, only show the first [_renderMessageLimit] messages. - // This will improve performance by only rendering a limited amount of messages - // instead of the entire history at all times. - return _messages.sublist(_messages.length - _renderMessageLimit); - } - /// If the chat should automatically scroll/jump to the latest message. @readonly var _autoScroll = true; diff --git a/lib/screens/channel/chat/stores/chat_store.g.dart b/lib/screens/channel/chat/stores/chat_store.g.dart index 700ff54d..dce8e323 100644 --- a/lib/screens/channel/chat/stores/chat_store.g.dart +++ b/lib/screens/channel/chat/stores/chat_store.g.dart @@ -9,14 +9,6 @@ part of 'chat_store.dart'; // ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic, no_leading_underscores_for_local_identifiers mixin _$ChatStore on ChatStoreBase, Store { - Computed>? _$renderMessagesComputed; - - @override - List get renderMessages => (_$renderMessagesComputed ??= - Computed>(() => super.renderMessages, - name: 'ChatStoreBase.renderMessages')) - .value; - late final _$_notificationAtom = Atom(name: 'ChatStoreBase._notification', context: context); @@ -252,8 +244,7 @@ mixin _$ChatStore on ChatStoreBase, Store { @override String toString() { return ''' -expandChat: ${expandChat}, -renderMessages: ${renderMessages} +expandChat: ${expandChat} '''; } }