mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
b039983f59
Moves the streaming performance tip into a reusable snippet and imports it on both the root headless page and the v2 basics headless-ui snippet (used by built-in-agent and a2a framework pages). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
18 lines
648 B
Plaintext
18 lines
648 B
Plaintext
## Performance tip: throttle streaming re-renders
|
|
|
|
When streaming long responses, the agent fires a re-render for every token. With many messages in the thread, this can cause jank. Two quick fixes:
|
|
|
|
1. **Throttle re-renders** — add `throttleMs` to cap update frequency:
|
|
|
|
```tsx
|
|
const { agent } = useAgent({ throttleMs: 50 }); // ~20 renders/sec
|
|
```
|
|
|
|
2. **Memoize message components** — wrap your message renderer in `React.memo` so only the streaming message re-renders:
|
|
|
|
```tsx
|
|
const Message = React.memo(({ msg }) => <p>{msg.content}</p>);
|
|
```
|
|
|
|
See the [useAgent performance docs](/reference/v2/hooks/useAgent#performance) for more details.
|