perf(ui): optimize text buffer and highlighting for large inputs (#16782)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
N. Taylor Mullen
2026-01-16 09:33:13 -08:00
committed by GitHub
parent fcd860e1b0
commit be37c26c88
10 changed files with 469 additions and 76 deletions
+9 -19
View File
@@ -4,34 +4,24 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { LRUMap } from 'mnemonist';
export class LruCache<K, V> {
private cache: Map<K, V>;
private maxSize: number;
private cache: LRUMap<K, V>;
constructor(maxSize: number) {
this.cache = new Map<K, V>();
this.maxSize = maxSize;
this.cache = new LRUMap<K, V>(maxSize);
}
get(key: K): V | undefined {
const value = this.cache.get(key);
if (value) {
// Move to end to mark as recently used
this.cache.delete(key);
this.cache.set(key, value);
}
return value;
return this.cache.get(key);
}
has(key: K): boolean {
return this.cache.has(key);
}
set(key: K, value: V): void {
if (this.cache.has(key)) {
this.cache.delete(key);
} else if (this.cache.size >= this.maxSize) {
const firstKey = this.cache.keys().next().value;
if (firstKey !== undefined) {
this.cache.delete(firstKey);
}
}
this.cache.set(key, value);
}