From 588b4de849b4ee7689ba33f84f0e2fa70e2f71f4 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 --- benchmark/assert/deepequal-object.js | 3 +- doc/api/assert.md | 12 +- lib/internal/util/comparisons.js | 268 ++++++++++++++------------- test/parallel/test-assert-deep.js | 22 ++- 4 files changed, 173 insertions(+), 132 deletions(-) diff --git a/benchmark/assert/deepequal-object.js b/benchmark/assert/deepequal-object.js index 80bb50f7982529..4238129b292b45 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 d40300cc3fdb1b..34107c7730fdd9 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -546,6 +546,10 @@ An alias of [`assert.ok()`][].