Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

perf: improve UI responsiveness by increasing stream update frequency and caching markdown renders

Salman Qureshibcd71065a290
diff --git a/src/channels/cli.ts b/src/channels/cli.ts
index 54516c1d..dd0746de 100644
--- a/src/channels/cli.ts
+++ b/src/channels/cli.ts
@@ -296,7 +296,7 @@ export class CLIChannel extends BaseChannel {
for await (const chunk of content) {
full += chunk;
const now = Date.now();
- if (now - lastRender >= 50) {
+ if (now - lastRender >= 16) {
this.update({
chatMessages: this.state.chatMessages.map((m) =>
m.id === msgId ? { ...m, content: full, streaming: true } : m,
diff --git a/src/ui/App.tsx b/src/ui/App.tsx
index d3dc67d0..416dca12 100644
--- a/src/ui/App.tsx
+++ b/src/ui/App.tsx
@@ -765,13 +765,21 @@ function SpotifyBody({ activeIdx, nowPlaying }: { activeIdx: number; nowPlaying:
function ChatMessagesView({ messages, agentName }: { messages: ChatMessage[]; agentName: string }) {
if (messages.length === 0) return null;
- const visible = messages.slice(-200);
+ const visible = messages.slice(-50);
+ const cache = React.useRef<Map<string, string>>(new Map());
return (
<Box flexDirection="column" flexGrow={1} paddingX={1}>
{visible.map((msg) => {
const roleColor = msg.role === 'user' ? 'yellow' : msg.role === 'system' ? 'gray' : 'cyan';
const prefix = msg.role === 'user' ? 'You' : msg.role === 'system' ? 'System' : agentName;
- const rendered = renderMarkdown(msg.content);
+ let rendered: string;
+ if (msg.streaming) {
+ rendered = renderMarkdown(msg.content);
+ cache.current.set(msg.id, rendered);
+ } else {
+ rendered = cache.current.get(msg.id) ?? renderMarkdown(msg.content);
+ cache.current.set(msg.id, rendered);
+ }
return (
<Box key={msg.id} flexDirection="column" marginBottom={1}>
<Box>