maraisr/object-identityPublic

chore: only track active objects for cycles

Before, every object, array, set, map etc lived in `seen` after it
was finished. That meant each new container paid a `indexOf` scan cost,
across all containers visited so far, which made wide objects scale
poorly.

Now, refs are pushed before walking and popped when done. Active
ancestors are still tracked, so cycle detection stays correct, but
completed refs no logner make sibling checks slower.

Which resulted in a 1.75x perf gain for wide objects, making us now the
fastest across the board. Small, or leaf-heavy objects stayed roughly
the same.

The tradeoff is that repeated, shared, non-cyclic refs are no longer
memoized, so the same large shared object may be walked again. But
common-case objects are unaffected.
MRMarais Rossouw authored
709e297Patch
Parent7aeaf22
2 files changed+78-78
StackedSplit
lib/mod.ts+10 −10
readme.md+68 −68