tupleson icon indicating copy to clipboard operation
tupleson copied to clipboard

feat: sync back-references

Open Sheraff opened this issue 2 years ago β€’ 1 comments

DISCLAIMERS:

  • this PR is a POC, code isn't very clean (the reference handling is done directly in the walkers, and not in its own neat plugin).
  • this PR was just a toy idea initially, there is absolutely no issue with simply throwing the code away

Add support for back-references:

  • support preserving identity of objects
    const a = {}
    const data = {
      foo: a,
      bar: a,
    }
    const res = tson.parse(tson.stringify(data))
    res.foo === res.bar // true
    
  • support circular references
    const data = {}
    data.foo = data
    const res = tson.parse(tson.stringify(data))
    data === data.foo // true
    

This PR also includes

  • changes in benchmark
    • use Intl.NumberFormat to format results
    • use process.memoryUsage to also log memory information (though I'm not sure how to interpret it, nor whether it's actually useful...)

This PR does not include

  • changes to async methods (serialize / deserialize) to enable back-references in these cases too

Sheraff avatar Oct 08 '23 17:10 Sheraff

Codecov Report

Attention: 20 lines in your changes are missing coverage. Please review.

Files Coverage Ξ”
src/sync/serialize.ts 100.00% <100.00%> (ΓΈ)
src/sync/deserialize.ts 86.11% <78.26%> (-13.89%) :arrow_down:

... and 5 files with indirect coverage changes

:loudspeaker: Thoughts on this report? Let us know!.

codecov[bot] avatar Oct 08 '23 17:10 codecov[bot]