aws-samples / aws-samples/bedrock-chat

[BUG] Excessive CPU and Memory Usage During Rendering of Long Responses

Open
#272 13 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
1.3k
Forks
535
Avg merge
1d 12h
Merged PRs (30d)
10

Description

## Describe the bug

When rendering long responses from the AI assistant, there is a significant increase in CPU and memory usage. This issue seems to be caused by the continuous re-rendering of the chat area as each character is streamed and appended to the response.

## To Reproduce

1. Open the chat application.
2. Send a prompt that would generate a long response from the AI assistant.
3. Observe the CPU and memory usage spiking as the response is being rendered character by character.

## Screenshots

## Additional context

- A warning is being displayed: "Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render."
- For a response of around 1000 characters, the memory usage can reach up to 2GB.
- The CPU and memory usage stabilize once the response rendering is complete.

Potential solutions:
- Implement a mechanism to control the re-rendering interval during the streaming process.
- Optimize the rendering process to minimize unnecessary re-renders.
- Investigate and address the root cause of the "Maximum update depth exceeded" warning.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue in the chat application with a long streamed response and observe CPU, memory, and the maximum-update-depth warning. Trace the chat rendering path to identify the repeated updates. Done means long responses render without the warning or excessive CPU and memory usage, while streaming remains functional.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.