mirror of
https://github.com/stablyai/orca.git
synced 2026-10-20 08:03:28 +00:00
perf(terminal): avoid rescanning cold restore payloads
This commit is contained in:
@@ -10,6 +10,15 @@ function payload(scrollback: string): ColdRestorePayload {
|
||||
}
|
||||
|
||||
describe('ColdRestorePayloadCache', () => {
|
||||
it('counts retained strings by UTF-16 code units', () => {
|
||||
expect(
|
||||
getColdRestorePayloadBytes({
|
||||
...payload('😀'),
|
||||
oscLinks: [{ row: 0, startCol: 0, endCol: 1, uri: 'é' }]
|
||||
})
|
||||
).toBe(54)
|
||||
})
|
||||
|
||||
it('evicts least-recently-used payloads to stay under its byte bound', () => {
|
||||
const first = payload('a'.repeat(100))
|
||||
const second = payload('b'.repeat(100))
|
||||
|
||||
@@ -13,8 +13,9 @@ export const MAX_COLD_RESTORE_CACHE_BYTES = 16 * 1024 * 1024
|
||||
|
||||
export function getColdRestorePayloadBytes(payload: ColdRestorePayload): number {
|
||||
const oscLinkBytes =
|
||||
payload.oscLinks?.reduce((bytes, link) => bytes + Buffer.byteLength(link.uri) + 24, 0) ?? 0
|
||||
return Buffer.byteLength(payload.scrollback) + Buffer.byteLength(payload.cwd) + oscLinkBytes + 16
|
||||
payload.oscLinks?.reduce((bytes, link) => bytes + link.uri.length * 2 + 24, 0) ?? 0
|
||||
// Why: code-unit sizing bounds V8 string storage without rescanning or flattening multi-MB ropes.
|
||||
return payload.scrollback.length * 2 + payload.cwd.length * 2 + oscLinkBytes + 16
|
||||
}
|
||||
|
||||
export class ColdRestorePayloadCache {
|
||||
|
||||
Reference in New Issue
Block a user