Skip to content

Conversation

@louis-jan
Copy link
Contributor

Describe Your Changes

This PR fixes the issue where the app UI becomes laggy while generating messages with tiny models. The performance issue is caused by poor state handling during message updates. Every time a token is yielded, the code loops through the messages array to check if a message is available before updating. This redundant operation is costly.

Before:
CleanShot 2024-12-23 at 20 27 29

After:
CleanShot 2024-12-23 at 20 29 45

Self Checklist

This pull request includes several changes aimed at improving the handling of thread-related state and message generation in the ModelHandler and related components. The most important changes include adding new atoms, updating imports, and modifying various hooks and components to support the new state management.

State Management Enhancements:

Component Updates:

  • web/containers/Providers/ModelHandler.tsx:

    • Imported the new atom and updated existing imports to include useAtom. [1] [2] [3]
    • Added state and effect hooks to manage the new subscribed generating message state and active thread state. [1] [2] [3] [4]
  • web/screens/Thread/ThreadCenterPanel/ChatItem/index.tsx:

    • Imported the new atom and updated existing imports to include useAtom. [1] [2]
    • Added state and effect hooks to manage the new subscribed generating message state within the ChatItem component.

These changes collectively enhance the state management related to thread handling and message generation, ensuring more robust and reactive behavior in the application.

@github-actions
Copy link
Contributor

Barecheck - Code coverage report

Total: 68.6%

Your code coverage diff: -0.06% ▾

Uncovered files and lines
FileLines
web/helpers/atoms/ChatMessage.atom.ts31, 33-34, 64, 88-89, 91-92, 94, 97-98, 105-106, 108, 111-112, 115-116, 127, 130-131, 136, 139-140, 144, 147-148, 150-151, 154, 170-175, 177, 180-181, 183-184, 186
web/hooks/useSetActiveThread.ts35, 37-38, 42-44, 54
web/screens/Thread/ThreadCenterPanel/ChatItem/index.tsx27-29, 32, 35, 38-42, 45, 48, 54-55, 58-59, 62-66

@github-actions
Copy link
Contributor

This is the build for this pull request. You can download it from the Artifacts section here: Build URL.

@louis-jan louis-jan merged commit b28cac7 into main Dec 23, 2024
21 checks passed
@louis-jan louis-jan deleted the fix/message-generating-performance-issue branch December 23, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants