Repository navigation
Commit 5d5f723
committed
[Perf]
`compact` tracked visited sub-objects in a plain array and tested membership with `refs.indexOf(val)` (O(n) per lookup),
so the final graph walk was O(V^2) in the number of distinct sub-objects.
Replace the array with a `side-channel` (already a dependency,
already used in this file for `overflowChannel`) for O(1) membership, making the walk O(V).
Membership semantics are identical, so circular-reference dedup is unchanged.
`side-channel` is WeakMap-backed on modern engines and degrades gracefully on old ones,
so this keeps `engines.node >= 0.6` (unlike a native `Set`/`WeakMap`).utils: make compact O(n) via a side-channel visited-set instead of Array.indexOf
1 parent 52afe00 commit 5d5f723
2 files changed
Lines changed: 18 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | | - | |
| 295 | + | |
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
| 305 | + | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
726 | 726 | | |
727 | 727 | | |
728 | 728 | | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
729 | 744 | | |
730 | 745 | | |
731 | 746 | | |
| |||
0 commit comments