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

🧐[问题]: 加载已有多段文本对话页面严重卡顿 #126

Open
liguobao opened this issue Mar 14, 2024 · 13 comments
Open

🧐[问题]: 加载已有多段文本对话页面严重卡顿 #126

liguobao opened this issue Mar 14, 2024 · 13 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@liguobao
Copy link

liguobao commented Mar 14, 2024

🧐 问题描述

1、大概是消耗了30W Token的对话,字数约等于 5W-10W
2、 此时继续对话,打字机效果吐字极慢。

      <ProChat
        displayMode={currentRow?.displayMode ?? "chat"}
        style={{ height: "calc(100vh - 150px)" }}
        chats={cachedChats}
        request={async (messages: any) => {

          const stream = OpenAIStream(response);
          return new StreamingTextResponse(stream);
        }}
      ></ProChat>
@liguobao liguobao changed the title 🧐[问题]: 下载多段文本对话(大概是消耗了30W Token的对话)严重卡顿 🧐[问题]: 加载多段文本对话页面严重卡顿 Mar 14, 2024
@liguobao liguobao changed the title 🧐[问题]: 加载多段文本对话页面严重卡顿 🧐[问题]: 加载已有多段文本对话页面严重卡顿 Mar 14, 2024
@ONLY-yours ONLY-yours added the help wanted Extra attention is needed label Mar 15, 2024
@ONLY-yours
Copy link
Collaborator

会不会是token多的时候模型本身返回就慢?

@liguobao
Copy link
Author

liguobao commented Mar 15, 2024 via email

@liguobao
Copy link
Author

liguobao commented Mar 15, 2024

是不是 chats={cachedChats} 这个导致的?还是说存在性能问题。
我的整个文本大概是55条,总大小约为14K

@sivdead
Copy link
Contributor

sivdead commented Mar 21, 2024

我也遇到了,
image
我这边一直在报这个错,不确定是我代码的问题还是什么

@liguobao
Copy link
Author

我也遇到了, image 我这边一直在报这个错,不确定是我代码的问题还是什么

好像还是框架的问题,等下修复吧。

@ONLY-yours ONLY-yours added the bug Something isn't working label Mar 22, 2024
@ONLY-yours
Copy link
Collaborator

ONLY-yours commented Mar 22, 2024

@liguobao @sivdead Memo 问题,之前写的Memo逻辑被后面的几个pr打挂了 - -

样本量小的时候无所谓,样本量大起来就会很卡

@ONLY-yours
Copy link
Collaborator

有一个 shouldUpdate 的 api 可以优化,先用这个 api 吧,默认的逻辑还在修

  /**
   * 判断组件是否需要更新。
   * @param nextProps - 下一个属性对象。
   * @returns 如果需要更新则返回 true,否则返回 false。
   */
  shouldComponentUpdate(nextProps: any) {
    if (nextProps.shouldUpdate) {
      return nextProps.shouldUpdate(this.props, nextProps);
    }
    try {
    // 这行默认对比现在一定是 true 所以就一直刷新了
      return !isEqual(this.props, nextProps);
    } catch (error) {
      return true;
    }
  }

  render() {
    return this.props.children;
  }
}

@liguobao
Copy link
Author

liguobao commented Mar 22, 2024

有一个 shouldUpdate 的 api 可以优化,先用这个 api 吧,默认的逻辑还在修

  /**
   * 判断组件是否需要更新。
   * @param nextProps - 下一个属性对象。
   * @returns 如果需要更新则返回 true,否则返回 false。
   */
  shouldComponentUpdate(nextProps: any) {
    if (nextProps.shouldUpdate) {
      return nextProps.shouldUpdate(this.props, nextProps);
    }
    try {
    // 这行默认对比现在一定是 true 所以就一直刷新了
      return !isEqual(this.props, nextProps);
    } catch (error) {
      return true;
    }
  }

  render() {
    return this.props.children;
  }
}

这个API怎么用来的? 没看懂。

试了下套个

  class MyProChat extends React.Component {

    shouldComponentUpdate(nextProps: any) {
      if (nextProps.shouldUpdate) {
        return nextProps.shouldUpdate(this.props, nextProps);
      }
      try {
        // 这行默认对比现在一定是 true 所以就一直刷新了
        return !isEqual(this.props, nextProps);
      } catch (error) {
        return true;
      }
    }
  return <ProChat></ProChat>;
}

好像没什么改善

@ONLY-yours
Copy link
Collaborator

我考虑了一些情况,认为一个某个 ChatItem 是否更新依靠四个东西

  • content 也就是内容
  • meta 一些头像元信息
  • loading 加载态和加载完成后
  • chatItemRenderConfig 需要自定义 Item 的配置

现在除开这四个进行变更外,其余情况,已经发送的 ChatItem 不会再次更新,commit 如下:
145b20c

@liguobao 至于现在用法来说,在 ProChat 上现在有这么一个 api:itemShouldUpdate
itemShouldUpdate?: (prevProps: ChatListItemProps, nextProps: ChatListItemProps) => boolean;
你可以参考默认的逻辑这么写:

<ProChat
     itemShouldUpdate=(prevProps,nextProps)=>{
      return (
        !isEqual(prevProps.content, nextProps?.content) ||
        !isEqual(prevProps.loading, nextProps?.loading) ||
        !isEqual(prevProps.chatItemRenderConfig, nextProps?.chatItemRenderConfig) ||
        !isEqual(prevProps.meta, nextProps?.meta)
      );
    }

/>

当然如果你不会动态设置 chatItemRenderConfig 和 Meta 参数,我认为 只用 content 和 loading 就可以了,默认逻辑会在下一个版本发布后修复

@liguobao
Copy link
Author

OK,我试试~感恩。

@ONLY-yours
Copy link
Collaborator

@liguobao @sivdead fixed in 1.12.2 试试

@liguobao
Copy link
Author

liguobao commented Mar 25, 2024 via email

@liguobao
Copy link
Author

@liguobao @sivdead fixed in 1.12.2 试试

更新了1.12.2,看起来是解决了。
不过整个长对话的渲染还是不够流畅,好像这种情况切到末尾的按钮也没有出来。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants