In performance-sensitive code paths, ensure you (1) don’t duplicate expensive async computations, (2) don’t do high-fanout git/network work before it’s necessary, and (3) when you must cap time/buffer/size, return partial results instead of failing or dropping all work.
How to apply
Example patterns 1) Reuse a single terminal snapshot for fallback + telemetry:
const terminalSnapshot = await returnCurrentTerminalContents(); // change this to return snapshot
telemetryService.captureTerminalOutputFailure(
terminalSnapshot.isTimeout ? terminalSnapshot.reason : terminalSnapshot.successReason
);
If changing the signature isn’t feasible, capture terminalSnapshot once at the call site and reuse it for both the emitted message and telemetry.
2) Batch git reads instead of spawning per file:
const input = [...new Set(oids)].join("\n");
if (!input) return new Map();
const { stdout } = await execFile("git", ["-C", cwd, "cat-file", "--batch"], {
windowsHide: true,
maxBuffer: Number.POSITIVE_INFINITY,
encoding: "buffer",
});
// parse stdout once
3) If caps are hit, emit partial telemetry/state rather than { state: "unavailable" }:
try {
// expensive read with strict limits
} catch (e) {
return { state: "partial", headInfo, dirtyFlags: undefined };
}
Team standard