mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-09-30 12:39:42 +02:00
perf: optimize screen manager and respawn controller
- Pre-compile ANSI escape and whitespace regex patterns in respawn controller - Pre-compile screen pattern regex for screen list parsing - Batch ps and pgrep calls in getScreensWithStats() for multiple screens - Reduces subprocess spawns from O(2n) to O(2) for n screens Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,10 @@ const MAX_RESPAWN_BUFFER_SIZE = 1024 * 1024;
|
||||
// Keep this much when trimming (512KB)
|
||||
const RESPAWN_BUFFER_TRIM_SIZE = 512 * 1024;
|
||||
|
||||
// Pre-compiled patterns for performance
|
||||
const ANSI_ESCAPE_PATTERN = /\x1b\[[0-9;]*[HJKmsu?lh]/g;
|
||||
const WHITESPACE_PATTERN = /\s+/g;
|
||||
|
||||
/**
|
||||
* Respawn sequence states
|
||||
*
|
||||
@@ -194,9 +198,10 @@ export class RespawnController extends EventEmitter {
|
||||
|
||||
// Filter out noise - only count meaningful data as activity
|
||||
// Ignore: cursor movements, color codes alone, small whitespace-only data
|
||||
// Uses pre-compiled patterns for performance
|
||||
const meaningfulData = data
|
||||
.replace(/\x1b\[[0-9;]*[HJKmsu?lh]/g, '') // Remove ANSI escape sequences
|
||||
.replace(/\s+/g, '') // Remove whitespace
|
||||
.replace(ANSI_ESCAPE_PATTERN, '') // Remove ANSI escape sequences
|
||||
.replace(WHITESPACE_PATTERN, '') // Remove whitespace
|
||||
.trim();
|
||||
|
||||
const isMeaningfulActivity = meaningfulData.length > 0;
|
||||
|
||||
Reference in New Issue
Block a user