mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-06 15:39:41 +02:00
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:
+12
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user