fix: high performance large convo rendering #4166
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe Your Changes
Enhance Jan’s convo rendering by virtualizing only the visible DOM nodes.
There was a performance issue on latest release 0.5.9, where it renders only a few tokens / second for a large convo (just around ~100 messages). After investigating, we found a few issues related to app state handling and top-level components re-rendering. We attempted to address these issues to minimize the likelihood of app re-rendering.
This pull request also addressed the issue where the conversation does not follow the generated text, which significantly impacts the user experience.
0.5.9 - Very laggy while generating

0.5.9 Nightly with better state handling

However, that’s not sufficient, we constantly strive for better UX. With this fix, we apply visible DOM node virtualization for enhanced performance and consistency, ensuring a seamless experience from small convo to any size of conversations.
Latest fix:

CleanShot.2024-11-30.at.16.47.15.mp4
A big shoutout to @tanstack/react-virtual for creating such an amazing library.
Changes made
Dependency Update:
@tanstack/react-virtual
(version^3.10.9
) inpackage.json
.Imports:
ErrorMessage
,ListContainer
) inChatBody
index file.useMemo
,useRef
, anduseVirtualizer
.Component Logic:
useVirtualizer
to efficiently render a virtualized list of chat messages.useRef
for the scrollable parent element and useuseMemo
to calculate the message count.Effects:
loadModelError
and adjusted scrolling logic upon data changes.Layout Adjustments:
ListContainer
with customdiv
elements to cater for virtualized rendering.LoadModelError
for a flexible layout.Minor Fixes:
?.
) in conditionals to prevent potential runtime errors when accessing properties of possibly undefined values.These changes improve performance, particularly in scenarios with large datasets by implementing efficient scrolling and rendering techniques.