Skip to content

assert: cap large assertion diffs#63379

Open
Sean-Kenneth-Doherty wants to merge 1 commit into
nodejs:mainfrom
Sean-Kenneth-Doherty:codex/assert-large-diff-cap
Open

assert: cap large assertion diffs#63379
Sean-Kenneth-Doherty wants to merge 1 commit into
nodejs:mainfrom
Sean-Kenneth-Doherty:codex/assert-large-diff-cap

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

Fixes: #62792

Summary

Default assertion diff output now avoids running the Myers diff over very large inspected values. For non-full diffs, if either inspected side has more than 1000 lines, the assertion error uses the existing truncated display path and marks the output as skipped.

This keeps small assertion messages unchanged, while avoiding worse-than-linear behavior for cases like assert.strictEqual(Buffer.alloc(n), [buffer]) where util.inspect() expands each byte to a separate line.

Benchmark

Using the patched lib/internal/assert/assertion_error.js through a targeted --expose-internals harness on this checkout:

1000 old=108.544ms new=2.187ms speedup=49.6x
2000 old=314.078ms new=0.643ms speedup=488.4x
4000 old=1583.674ms new=2.344ms speedup=675.7x

A new benchmark case is included in benchmark/assert/strict-equal-buffer-array.js.

Tests

  • node --check lib/internal/assert/assertion_error.js
  • node --check test/parallel/test-assert.js
  • node --check benchmark/assert/strict-equal-buffer-array.js
  • git diff --check
  • make lint-js LINT_JS_TARGETS="lib/internal/assert/assertion_error.js test/parallel/test-assert.js benchmark/assert/strict-equal-buffer-array.js"
  • targeted patched-module smoke test up to Buffer.alloc(16000)

I also ran python3 configure.py --ninja successfully. I started ninja -C out/Release node -j8, but stopped it because it was still compiling ICU at 236/4772 steps and had not reached a usable out/Release/node binary.

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. needs-ci PRs that need a full CI run. labels May 17, 2026
@Sean-Kenneth-Doherty
Copy link
Copy Markdown
Author

Follow-up validation on the current head (1a8978d):

  • node --check lib/internal/assert/assertion_error.js -> passed
  • node --check test/parallel/test-assert.js -> passed
  • node --check benchmark/assert/strict-equal-buffer-array.js -> passed
  • make lint-js LINT_JS_TARGETS="lib/internal/assert/assertion_error.js test/parallel/test-assert.js benchmark/assert/strict-equal-buffer-array.js" -> completed after installing tools/eslint deps; JS linter passed
  • git diff --check origin/main...HEAD && git diff --check -> clean
  • focused node --expose-internals harness loaded the patched lib/internal/assert/assertion_error.js and constructed AssertionError for Buffer.alloc(1000/2000/4000/8000/16000) vs [buffer]; every case emitted the skipped-lines marker, stayed at 27 message lines, and completed in about 2.0ms / 2.5ms / 2.4ms / 4.9ms / 7.3ms respectively

I also tried to produce a local patched out/Release/node: python3 configure.py --ninja succeeded, and python3 configure.py --ninja --without-intl also succeeded with the expected Temporal-without-ICU warning, but even the lean ninja -C out/Release node -j8 path was still deep in the V8/OpenSSL build after several minutes, so I stopped it cleanly rather than burn unrelated compile time. The branch is clean locally after these checks.

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty marked this pull request as ready for review May 17, 2026 07:47
@Sean-Kenneth-Doherty Sean-Kenneth-Doherty changed the title [codex] assert: cap large assertion diffs assert: cap large assertion diffs May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assert Issues and PRs related to the assert subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worse-than-linear assert performance for trivial mismatch

2 participants