Files
copilotkit__copilotkit/docs/snippets/shared/performance-tip.mdx
Maxim b039983f59 docs: extract performance tip into shared snippet
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>
2026-04-03 20:00:02 +02:00

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.