Skip to content

Latest commit

 

History

History
17 lines (11 loc) · 648 Bytes

File metadata and controls

17 lines (11 loc) · 648 Bytes

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:
const { agent } = useAgent({ throttleMs: 50 }); // ~20 renders/sec
  1. Memoize message components — wrap your message renderer in React.memo so only the streaming message re-renders:
const Message = React.memo(({ msg }) => <p>{msg.content}</p>);

See the useAgent performance docs for more details.