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

Commit

Permalink
fix: Fix Chrome stack overflow during highlighting (#64072)
Browse files Browse the repository at this point in the history
Using the spread operator with large arrays can trigger a
stack overflow in Chrome/V8. For example, see:
- nodejs/node#16870

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.

![](https://github.com/user-attachments/assets/e096c664-063e-44ed-a991-72629af36651)

## Changelog

- Fixes a Chrome-specific stack overflow when highlighting large files.
  • Loading branch information
varungandhi-src authored Jul 25, 2024
1 parent 1503614 commit 2644e24
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion client/web/src/repo/blob/codemirror/codeintel/occurrences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ export class OccurrenceIndex extends Array<Occurrence> {
previousEndline = current.range.end.line
}

super(...nonOverlappingOccurrences(occurrences))
// CAUTION: Do not "optimize" this to super(...nonOverlappingOccurrences(occurrences))
// as Chrome will push all elements to a stack, and potentially trigger a stack overflow.
// Similar bug in Nodejs: https://github.com/nodejs/node/issues/16870
super()
for (const occ of nonOverlappingOccurrences(occurrences)) {
this.push(occ)
}
this.lineIndex = lineIndex
}

Expand Down

0 comments on commit 2644e24

Please sign in to comment.