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

Prevent the 'Message' components from unexpectedly re-rendering while receiving tokens #1051

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

0xez
Copy link

@0xez 0xez commented Jun 3, 2024

While receiving tokens from the server, the 'updateMessageContentById' function will create new objects for all the messages having 'steps' member, which will modify the references values of the messages and cause all the 'Message' components based on those messages to rerender. If we have a long conversations, like 100 rounds, this may cause serious performance problem.

This patch tried to fix it by checking if the messages really changed and only creating new objects for changed ones.

Meanwhile, given that only one message need to be updated and for most of the cases the last one, this patch also make some performance optimization by iterating from the last element and break the loop when finding matched one.

… tokens

While receiving tokens from the server, the  'updateMessageContentById' function will create new objects for all the messages having 'steps' member, which will modify the references value of the messages and cause all the 'Message' components based on those messages to rerender. If we have a long conversations, like 100 rounds, this may cause serious performance problem.

This patch tried to fix it by checking if the messages really changed and only creating new objects for changed ones.

Meanwhile, given that only one message need to be updated and for most of the cases the last one, this patch also make some performance optimization by iterating from the last element and break the loop when finding matched one.
@0xez 0xez changed the title Some 'Message' components rerender unexpectedly while receiving tokens Prevent the 'Message' components from unexpected rerenderings while receiving tokens Jun 3, 2024
@0xez 0xez changed the title Prevent the 'Message' components from unexpected rerenderings while receiving tokens Prevent the 'Message' components from unexpectedly re-rendering while receiving tokens Jun 3, 2024
@dokterbob dokterbob added the bug Something isn't working label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants