Problem
apps/desktop/src/main/gateway/deepseek/state.ts L114–123
private prune(): void {
while (this.recordOrder.length > this.limit) {
const id = this.recordOrder.shift()!; // O(n) left-shift
this.records.delete(id);
}
while (this.textOrder.length > this.limit) {
const key = this.textOrder.shift()!; // O(n)
this.textRecords.delete(key);
}
}
Array.shift() is an O(n) operation that shifts every remaining element on each eviction. With a default limit of 1024, this fires frequently during heavy tool-call workloads.
Suggested fix
Replace shift() with a circular index (ring buffer) or an index: number pointer to bring prune down to O(1). Alternatively, use a proper deque such as the denque package.
Problem
apps/desktop/src/main/gateway/deepseek/state.tsL114–123Array.shift()is an O(n) operation that shifts every remaining element on each eviction. With a default limit of 1024, this fires frequently during heavy tool-call workloads.Suggested fix
Replace
shift()with a circular index (ring buffer) or anindex: numberpointer to bring prune down to O(1). Alternatively, use a proper deque such as thedenquepackage.