perf: optimize hot paths across server, session, and frontend

- Pre-compile regex patterns (ANSI escape, token parsing) in session.ts
- Optimize SSE broadcast to serialize JSON once for all clients
- Add DOM element caching ($() helper) to avoid repeated getElementById
- Throttle resize observer with dimension change detection
- Use array.join() for session tab HTML building
- Replace DOM-based escapeHtml with regex replacement
- Cache toast container reference

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-19 11:48:02 +01:00
co-authored by Claude Opus 4.5
parent 0af813b3c4
commit ce61a3b2f2
3 changed files with 152 additions and 56 deletions
+12 -1
View File
@@ -1160,9 +1160,20 @@ export class WebServer extends EventEmitter {
}
}
// Optimized: send pre-formatted SSE message to a client
private sendSSEPreformatted(reply: FastifyReply, message: string): void {
try {
reply.raw.write(message);
} catch {
this.sseClients.delete(reply);
}
}
private broadcast(event: string, data: unknown): void {
// Performance optimization: serialize JSON once for all clients
const message = `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
for (const client of this.sseClients) {
this.sendSSE(client, event, data);
this.sendSSEPreformatted(client, message);
}
}