perf(json): use FxHashSet for cycle detection in JSON.stringify#5145
perf(json): use FxHashSet for cycle detection in JSON.stringify#5145iammdzaidalam wants to merge 4 commits intoboa-dev:mainfrom
Conversation
Test262 conformance changes
Tested main commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5145 +/- ##
===========================================
+ Coverage 47.24% 59.80% +12.56%
===========================================
Files 476 582 +106
Lines 46892 63490 +16598
===========================================
+ Hits 22154 37972 +15818
- Misses 24738 25518 +780 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @jedel1043, small perf change for JSON cycle detection, would appreciate a review. |
a simple test that actually uses |
|
Yeah, that makes sense. If |
|
Added focused
I tried running them with Left that as a separate follow-up rather than expanding this PR. |
Test262 conformance changes
Tested main commit: |
then dont use the cargo bench. run the script manually and time it (remember to add a loop though). and compare the time between pr and main. |
|
yeah, fair. will just time it manually with a loop on main vs this PR and post numbers. |
|
Ran the scripts manually through On my machine (after warmup), timings were roughly: Deep case:
Circular case:
The deep acyclic case shows a small improvement on this branch, while the circular case is roughly flat and within noise. This is just a quick manual check, not a rigorous benchmark. |
df73b26 to
7d5d594
Compare
7d5d594 to
67e5836
Compare
BenchmarkRan the focused stringify scripts manually through Deep case (acyclic object)
Circular case (cycle detection)
Notes
|
67e5836 to
3fbccc7
Compare
Description
JSON.stringifycurrently performs cycle detection using linear scans over the active stack.This replaces those checks with an
FxHashSet, while keeping the existing traversal order in aVec.StateRecordnow stores:stack: Vec<JsObject>stack_set: FxHashSet<JsObject>Both are updated together in
serialize_json_objectandserialize_json_array.Behavior remains unchanged, only the lookup strategy is different.
Changes
FxHashSetfor cycle detectionVecfor orderTests
Added tests for:
Notes
Ran local checks (
fmt,check,clippy,tests).Tried running
cargo bench -p boa_benches, but the suite hit a stack overflow inv8-benches/deltablue, so not using it as validation for this change.