fix(internal): improve safeStringify function to handle circular references more effectively
Merged
RA
10mo ago+35+35+01234567890123456789-23-23-01234567890123456789
Fixes #960
What is the current behavior?
Very slow processing of safeStringify
What is the new behavior?
On my test processing time reduced from 89000ms to 1ms.
Summary by cubic
Improved safeStringify to correctly handle circular references and run dramatically faster. The replacer now tracks the traversal stack and marks cycles as "[Circular]" while respecting toJSON; observed time drops from ~89s to ~1ms.
- Refactors
- Replaced deep-copy recursion with a stack-based circular check in the replacer.
- Removed manual object reconstruction; rely on JSON.stringify for traversal.
- Apply toJSON safely before detecting cycles.
Summary by CodeRabbit
-
Bug Fixes
- Improved serialization to more reliably handle circular and complex data structures.
-
Chores
- Added release metadata for a patch update.
✏️ Tip: You can customize this high-level summary in your review settings.