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

关于messages重复渲染的问题 #5837

Open
liukkm opened this issue Nov 18, 2024 · 5 comments
Open

关于messages重复渲染的问题 #5837

liukkm opened this issue Nov 18, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@liukkm
Copy link

liukkm commented Nov 18, 2024

🥰 需求描述

I have verified this project, and when there are many conversations and chats, the browser will get stuck and the memory will skyrocket. After checking the general reasons, I found that it is because all Message-items on the page will be rendered repeatedly when returning from each Q&A. I added console.log() to message.map, and found that message-item would be repeatedly rendered about 10 times when entering the page for the first time. When text stream was output, message-item would be repeatedly rendered and the number of rendering times was the length of text stream.
image
image

When there are 20-40 chats in a session or when the length of each text stream is much longer, the whole system freezes.

🧐 解决方案

Do not over-render, update only the corresponding message-item each time the text stream returns, and do not render the other message-items repeatedly

📝 补充信息

No response

@liukkm liukkm added the enhancement New feature or request label Nov 18, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: About the problem of repeated rendering of messages

Copy link
Member

这里是一个列表渲染的逻辑,前端框架针对列表渲染的时候,确实不好做diff

可以的优化方向是将最新的一条消息作为currentMessage提出来单独渲染,剩下的messages整体渲染。
另外,这里可以将单独一条message抽象出一个组件进行渲染。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Here is a list rendering logic. When the front-end framework renders the list, it is really difficult to do diff.

The possible optimization direction is to present the latest message as currentMessage and render it separately, and render the remaining messages as a whole.
In addition, a single message can be abstracted into a component for rendering.

@liukkm
Copy link
Author

liukkm commented Nov 18, 2024

目前我已经抽离出一个message-item的组件
至于您说的currentMessage似乎没那么好处理,因为这个涉及到多会话问题 以及 上一个问答未结束下一个问答已发起的问题,对此你有什么想法吗?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


At present, I have extracted a message-item component
As for your currentMessage, it seems that it is not easy to handle, because it involves multi-session issues and the issue of the previous Q&A not being completed and the next Q&A having been initiated. Do you have any thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants