Git Product home page Git Product logo

Comments (9)

AsyncBanana avatar AsyncBanana commented on August 31, 2024 2

I will try to benchmark this later. If the results show that cyclical reference checking slows nested objects down enough, I will add an option to disable the checking.

from microdiff.

AsyncBanana avatar AsyncBanana commented on August 31, 2024 2

I decided to add an option in v1.2.0, so by default, cycles are checked, but you can disable it as specified in the README and release notes.

from microdiff.

infostreams avatar infostreams commented on August 31, 2024 1

Benchmark it.

from microdiff.

infostreams avatar infostreams commented on August 31, 2024

Don't be silly, the overhead in both complexity, memory use, and code size is negligible (see for yourself 3b6ab8f), and it serves the important purpose of not creating situations where using this library would potentially crash the process or exhaust your server's memory. For such a small addition (less than 2 lines of code) that's a huge win.

from microdiff.

majg0 avatar majg0 commented on August 31, 2024

That totally depends on the size of the objects. If the user knows that there are no circular references, why have the runtime check it at all?

For big JSON blobs with many objects, this will severely impact performance by having to

  1. reallocate the array
  2. linearly search for references for every addition

Sure, it is assumed that it is small, but performance almost doesn't matter in the small anyway, so why micro-optimize then?

from microdiff.

majg0 avatar majg0 commented on August 31, 2024

I don't have the incentive to put that amount of time in, I don't even use the lib. Just wanted to put this issue out there.

from microdiff.

AsyncBanana avatar AsyncBanana commented on August 31, 2024

For most objects with low depth, as expected, there is little to no difference. However, with highly nested objects, I noticed a difference of around 30%. Should I add an option to disable it? Having the choice would increase code size slightly and reduce performance slightly, but it would overall be faster if you disable checking, and you can still keep checking if you want.

from microdiff.

majg0 avatar majg0 commented on August 31, 2024

Great work! 🎉🙌

One thing we could try before using a flag is to use a Set instead of an Array. How does that affect performance?

I think a 3% pessimization or so is where I'd feel alright about it personally, because if one only diffs large JSON blobs which just arrived serialized over the network, there is no need to check for circular dependencies, so it would feel silly to miss out on something like every 20th diff (in the case of 5% e.g.)

from microdiff.

majg0 avatar majg0 commented on August 31, 2024

Nicely done!

from microdiff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.