Files
orca/src/main/ipc/filesystem-watcher-event-batch.ts
T
Neil e0e9807cc6 Avoid retaining oversized watcher event batches
Follow-up to #2419: mark oversized filesystem watcher batches as overflow at enqueue time so the app does not retain thousands of paths before sending the conservative refresh.
2026-05-20 01:35:56 -07:00

39 lines
1.0 KiB
TypeScript

import type { Event as WatcherEvent } from '@parcel/watcher'
export const MAX_BATCHED_WATCHER_EVENTS = 5_000
export type WatcherEventBatchState = {
events: WatcherEvent[]
overflowed: boolean
}
export function appendWatcherEvents(
batchEvents: WatcherEvent[],
incomingEvents: WatcherEvent[]
): void {
// Why: worktree deletion can deliver enough events that `push(...events)`
// exceeds V8's argument limit and crashes the main process.
for (const event of incomingEvents) {
batchEvents.push(event)
}
}
export function queueWatcherEvents(
batch: WatcherEventBatchState,
incomingEvents: WatcherEvent[]
): void {
if (batch.overflowed) {
return
}
if (batch.events.length + incomingEvents.length > MAX_BATCHED_WATCHER_EVENTS) {
// Why: once precision is too expensive, keeping every path only burns
// memory before flush sends the same conservative overflow refresh.
batch.events = []
batch.overflowed = true
return
}
appendWatcherEvents(batch.events, incomingEvents)
}