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 <ruben@bridgewater.de>
PR-URL: https://github.com/nodejs/node/pull/46593
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Ruben Bridgewater authored and Michaël Zasso committed 2023-03-13 11:27:42 +01:00
1 parent abba45e120
commit 7f85a2cb6f
4 files changed
+176 -133

No files matched your search

+17 -5
View File
@@ -419,21 +419,33 @@ assertNotDeepOrStrict(
// GH-14441. Circular structures should be consistent
{
const a = {};
const b = {};
a.a = a;
const b = {};
b.a = {};
b.a.a = a;
assertDeepAndStrictEqual(a, b);
assertNotDeepOrStrict(a, b);
}
{
const a = {};
a.a = a;
const b = {};
b.a = b;
const c = {};
c.a = a;
assertNotDeepOrStrict(b, c);
}
{
const a = new Set();
const b = new Set();
const c = new Set();
a.add(a);
const b = new Set();
b.add(b);
const c = new Set();
c.add(a);
assertDeepAndStrictEqual(b, c);
assertNotDeepOrStrict(b, c);
}
// https://github.com/nodejs/node-v0.x-archive/pull/7178