Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 8cf3916

Browse files
[Backport 5.5.x] fix: Fix Chrome stack overflow during highlighting (#64074)
Using the spread operator with large arrays can trigger a stack overflow in Chrome/V8. In a highlighting context, we can have 10k-100k occurrences in a file, so let's avoid using the spread operator. Fixes https://linear.app/sourcegraph/issue/GRAPH-772 ## Test plan Manually tested against sample file. ![CleanShot 2024-07-25 at 11 10 43@2x](https://github.com/user-attachments/assets/e096c664-063e-44ed-a991-72629af36651) ## Changelog - Fixes a Chrome-specific stack overflow when highlighting large files. <br> Backport 2644e24 from #64072 Co-authored-by: Varun Gandhi <[email protected]>
1 parent 72ab1f8 commit 8cf3916

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

client/web/src/repo/blob/codemirror/codeintel/occurrences.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ export class OccurrenceIndex extends Array<Occurrence> {
5050
previousEndline = current.range.end.line
5151
}
5252

53-
super(...nonOverlappingOccurrences(occurrences))
53+
// CAUTION: Do not "optimize" this to super(...nonOverlappingOccurrences(occurrences))
54+
// as Chrome will push all elements to a stack, and potentially trigger a stack overflow.
55+
// Similar bug in Nodejs: https://github.com/nodejs/node/issues/16870
56+
super()
57+
for (const occ of nonOverlappingOccurrences(occurrences)) {
58+
this.push(occ)
59+
}
5460
this.lineIndex = lineIndex
5561
}
5662

0 commit comments

Comments
 (0)