-
Notifications
You must be signed in to change notification settings - Fork 56.9k
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
perf: memorize markdown rendering #496
Conversation
Markdown rendering can take time. Use `React.memo` for better performance. The improvement is especially visible if there are complex elements. For example, a `<Chat />` with an output of `如何推导三次方程求根方程?` (which uses latex) now renders in about 5ms, down from ~140ms. Related: ChatGPTNextWeb#302
Someone is attempting to deploy a commit to a Personal Account owned by @Yidadaa on Vercel. @Yidadaa first needs to authorize it. |
可能需要看一下 React.memo 的实现,如果不小心可能导致 stream 输出时占用 O(N^2) 的内存 |
大致看了一下,memo 不会导致 O(N^2) 内存占用。 |
我目前已经在代码中提供了一个 lazy load 的 hook,但是还没有实装,建议配合使用,需要把 message 提取成一个单独的组件。 |
顺便能否提供一下 memo 前后的 performance 截图对比? |
之前: before.webm之后: after.webm之所以选择 Markdown 是因为它的 props 非常简单,只有一个字符串,容易对比,并且在 profiling 中占用了绝大部分时间。其他组件的 props 有可能直接或间接被各种配置影响。 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
牛逼,马上合入 |
perf: memorize markdown rendering
Markdown rendering can take time. Use
React.memo
for better performance.The improvement is especially visible if there are complex elements. For example, a
<Chat />
with an output of如何推导三次方程求根方程?
(which uses latex) now renders in about 5ms, down from ~140ms.Related: #302