Skip to content
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

Unnecessary Rebuilds #80

Open
Yogesh-Dubey-Ayesavi opened this issue Mar 27, 2023 · 4 comments
Open

Unnecessary Rebuilds #80

Yogesh-Dubey-Ayesavi opened this issue Mar 27, 2023 · 4 comments
Labels
P2 Priority

Comments

@Yogesh-Dubey-Ayesavi
Copy link
Contributor

I just added to debugPrint('${widget.message.id} rebuilt'); to MessageView build method .

The logs i obtained then.

a0e30af0-daa0-46fa-a1f8-54af63a743ac.mp4

Each message even which are outside the viewPort are getting rebuilt, that causes huge memory consumption.

@Yogesh-Dubey-Ayesavi
Copy link
Contributor Author

Yogesh-Dubey-Ayesavi commented Mar 28, 2023

I figured out the problem, SingleChildScrollView is the responsible widget.

Since the _chatStreamBuilder method is embedded inside SingleChildScrollView so it builds each items at once, which in context with performance is not so good solution.

I tried removing SingleChildScrollView like this.

GestureDetector(
      onHorizontalDragUpdate: (details) => isEnableSwipeToSeeTime
          ? showPopUp
              ? null
              : _onHorizontalDrag(details)
          : null,
      onHorizontalDragEnd: (details) => isEnableSwipeToSeeTime
          ? showPopUp
              ? null
              : _animationController?.reverse()
          : null,
      onTap: widget.onChatListTap,
      child: Column(
        children: [
          Flexible(
            child: _animationController != null
                ? AnimatedBuilder(
                    animation: _animationController!,
                    builder: (context, child) {
                      return _chatStreamBuilder;
                    },
                  )
                : _chatStreamBuilder,
          ),
          TypingIndicator(
            typeIndicatorConfig: widget.typeIndicatorConfig,
            chatBubbleConfig: chatBubbleConfig?.inComingChatBubbleConfig,
            showIndicator: showTypingIndicator,
            profilePic: profileCircleConfig?.profileImageUrl,
          ),
          SizedBox(
            height: MediaQuery.of(context).size.width *
                (widget.replyMessage.message.isNotEmpty ? 0.3 : 0.14),
          ),
        ],
      ),
    );

physics: const NeverScrollableScrollPhysics(),

- physics: const NeverScrollableScrollPhysics(),  
+ controller: widget.scrollController,

scrollController.position.minScrollExtent,

+scrollController.position.maxScrollExtent,

After making these changes guess what, it worked nicely.

Note

Using this method performance can be improved until an extent but, scrollingToReplyMessages will take a lot of time because GroupedListView is built on top of ListView.builders. I suggest using scrollable_positioned_list or scrollable_positioned_list_extended(with helper methods like scrollToMax extent and notification listeners) inside custom fork of GroupedList we can reach to threaded messages instantly.

@DhvanitVaghani
Copy link
Contributor

@Yogesh-Dubey-Ayesavi Thanks for pointing out these issues. We had planned for this performance improvement, but you suggested some changes, I will try those and give feedback on this

@github-actions
Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions
Copy link

github-actions bot commented May 2, 2023

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions bot closed this as completed May 2, 2023
@apurva010 apurva010 added the P2 Priority label May 17, 2024
@apurva010 apurva010 reopened this Jun 4, 2024
@apurva010 apurva010 removed the stale label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Priority
Projects
None yet
Development

No branches or pull requests

3 participants