From 7f85a2cb6fc137ced88c8df1faad982cc79bd3fd Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 9 Feb 2023 22:12:25 +0100 Subject: [PATCH] assert,util: improve deep equal comparison performance This is mainly a performance improvement for a lot of simple cases. Diverging elements are detected earlier and equal entries are partially also detected faster. A small correctness patch is also included where recursions now stop as soon as either side has a circular structure. Before, both sides had to have a circular structure at the specific comparison which could have caused more checks that likely fail at a later point. Signed-off-by: Ruben Bridgewater PR-URL: https://github.com/nodejs/node/pull/46593 Reviewed-By: Yagiz Nizipli Reviewed-By: James M Snell Reviewed-By: Matteo Collina --- benchmark/assert/deepequal-object.js | 3 +- doc/api/assert.md | 12 +- lib/internal/util/comparisons.js | 272 +++++++++++++++------------ test/parallel/test-assert-deep.js | 22 ++- 4 files changed, 176 insertions(+), 133 deletions(-) diff --git a/benchmark/assert/deepequal-object.js b/benchmark/assert/deepequal-object.js index 80bb50f7982..4238129b292 100644 --- a/benchmark/assert/deepequal-object.js +++ b/benchmark/assert/deepequal-object.js @@ -12,7 +12,8 @@ const bench = common.createBenchmark(main, { combinationFilter: (p) => { return p.size === 1e4 && p.n === 25 || p.size === 1e3 && p.n === 2e2 || - p.size === 1e2 && p.n === 2e3; + p.size === 1e2 && p.n === 2e3 || + p.size === 1; }, }); diff --git a/doc/api/assert.md b/doc/api/assert.md index d40300cc3fd..34107c7730f 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -546,6 +546,10 @@ An alias of [`assert.ok()`][].