vscode icon indicating copy to clipboard operation
vscode copied to clipboard

arrays.delta() throws "Maximum call stack size exceeded" for large arrays

Open mant-raj opened this issue 1 week ago • 0 comments

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.148.0 (main @ 41004e061e582855eb1e99b6a6e5d52994f661be)
  • OS Version:

Steps to Reproduce:

  1. Run the following against src/vs/base/common/arrays.ts:
import { delta } from './arrays';

const before = Array.from({ length: 200000 }, (_, i) => i);
delta(before, [], (a, b) => a - b);
  1. It throws RangeError: Maximum call stack size exceeded.

Cause

delta (lines ~278-280) uses spread inside push:

removed.push(...before.slice(splice.start, splice.start + splice.deleteCount));
added.push(...splice.toInsert);

Spreading a large array passes every element as a function argument, which overflows the call stack. sortedDiff has the same pattern at line ~229 (latest.toInsert.push(...toInsert)).

Suggested fix

Push in a loop instead of spreading:

for (const item of before.slice(splice.start, splice.start + splice.deleteCount)) {
	removed.push(item);
}
for (const item of splice.toInsert) {
	added.push(item);
}

Impact

delta is used by the SCM history view, configuration service, extension management services and extHostWorkspace, so a large input (e.g. a repo with a very large history) could hit this.

mant-raj avatar Nov 18 '26 17:11 mant-raj