mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:12:02 +00:00
fix: Fix Chrome stack overflow during highlighting (#64072)
Using the spread operator with large arrays can trigger a stack overflow in Chrome/V8. For example, see: - https://github.com/nodejs/node/issues/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.  ## Changelog - Fixes a Chrome-specific stack overflow when highlighting large files.
This commit is contained in:
parent
15036143bc
commit
2644e24244
@ -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
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user