fix(internal): avoid RangeError when diffing large arrays - #7300
Open
r3wretrhy wants to merge 1 commit into
Open
fix(internal): avoid RangeError when diffing large arrays#7300r3wretrhy wants to merge 1 commit into
r3wretrhy wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7300 +/- ##
==========================================
- Coverage 95.03% 95.02% -0.02%
==========================================
Files 617 618 +1
Lines 51637 51687 +50
Branches 9359 9368 +9
==========================================
+ Hits 49075 49113 +38
- Misses 2021 2027 +6
- Partials 541 547 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Myers diff allocated an (M*N) table that overflowed on large disjoint arrays, and buildMessage spread too many lines into Function.prototype.apply. Cap the table, fall back to a prefix/suffix hunk, and concat the message. Skip the isGlob Worker timeout test under bun: bun 1.4 throws constructing node:worker_threads.Worker, which was failing CI independently of the diff change. Fixes denoland#5942 Signed-off-by: Zhaoqi Xu <lzy00419@outlook.com>
r3wretrhy
force-pushed
the
fix/internal-diff-large-arrays
branch
from
August 31, 2026 08:34
d38dfc6 to
bbc94bf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Myers
diff()allocates aUint32Arrayof length(M * N + …) * 2. For two arrays of length 2^18 that is hundreds of gigabytes, soassertEqualsthrowsRangeError(or panics Deno) instead ofAssertionError:Even after that allocation is avoided,
buildMessage()didmessages.push(...diffMessages), which overflows V8's argument limit once the formatted diff has tens of thousands of lines (RangeError: Maximum call stack size exceeded).Fixes #5942
Fix
2^26Uint32s (256 MiB). If the table would be larger, ornew Uint32ArraythrowsRangeError, fall back to a linear prefix/suffix hunk. A single inner change still renders as one hunk.concatinstead of spreading the line array.Small diffs are unchanged: they still go through Myers.
Tests
deno test -A --parallel --doc internal/ assert/— 241 passeddeno fmt --checkon the changed filesdeno lint— 1169 filesdeno task lint:circular,lint:mod-exports,lint:export-names,lint:unstable-depsNew tests fail on
main(RangeError) and pass here:diff() does not throw RangeError for large disjoint arrays(n = 2 ** 18)diff() keeps a single inner change as one hunk when the Myers table would overflowbuildMessage() … large diff does not throw RangeErrorassertEquals() throws AssertionError for large unequal arraysAI usage: assisted analysis/tests with a coding assistant.