Commit 8c60fb4
SAGE
perf(voiceclaw-realtime, server-maintenance): audit-driven hot-path wins
Acted on the SAGE-side optimization audit (~/Documents/sage/self-improvement-audit/report.md, openclaw section).
#1 β xai-realtime.ts:719 β replace per-overflow O(n) `.shift()` with batched 25% splice. Hot voice path; under sustained overflow the old shift-per-push was N*overflow_count. Batch trim drops 25% in one splice so amortized per-push cost is O(1) (audio overflow always meant data loss anyway; trimming a quarter at once is cleaner than dropping one frame at a time).
#7 β server-maintenance.ts:93 β `[...map.entries()].toSorted(...)` allocates two distinct copies (spread + toSorted internal). Switched to single Array.from(...) + in-place .sort(). Drops one allocation per maintenance tick.
#8 β xai-realtime.ts:698 + isValidXaiVoice β `.find()` / `.includes()` over the const XAI_VOICES tuple was O(N) per voice resolution. Pre-built `_XAI_VOICE_SET = new Set(XAI_VOICES)`; lookups are now O(1).
Skipped #2 (audit suggested merging 4 server-maintenance Map iterations into one β they touch DIFFERENT collections; merging would be artificial code, not real perf).
Multi-day refactors of attempt.ts / loader.ts / chat.ts deferred per audit recommendation.1 parent 6854786 commit 8c60fb4
2 files changed
Lines changed: 21 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
94 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
95 | 100 | | |
96 | 101 | | |
97 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| |||
695 | 699 | | |
696 | 700 | | |
697 | 701 | | |
698 | | - | |
699 | | - | |
| 702 | + | |
| 703 | + | |
700 | 704 | | |
701 | 705 | | |
702 | 706 | | |
703 | | - | |
| 707 | + | |
| 708 | + | |
704 | 709 | | |
705 | 710 | | |
706 | 711 | | |
| |||
716 | 721 | | |
717 | 722 | | |
718 | 723 | | |
719 | | - | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
720 | 730 | | |
721 | 731 | | |
722 | 732 | | |
| |||
0 commit comments