AsyncBanana / microdiff

A fast, zero dependency object and array comparison library. Significantly faster than most other deep comparison libraries and has full TypeScript support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Loops / infinite recursion

infostreams opened this issue · comments

If you try to diff structures that have a loop in it, your diff algorithm will hang and enter infinite recursion and therefore exhaust system resources until the tab or the process hangs.

I am looking for a solution that will not decrease performance or increase size much, but it might take a bit to figure something out. If you have any good ideas on how to do this, feel free to submit a PR.

Thanks! However, the problem is those algorithms take up more space, and, more importantly, they would significantly decrease performance for objects. Currently, this probably will not be solved, although I might eventually make an extension to the core library for checking for circular references.

Ha! That's a bad decision. Who cares about speed if using your library could potentially hang MY application? This will bite some people, I can guarantee it.

Generally, you should avoid practices that could cause circular references as it is. However, if you cannot do that, you can implement circular reference checking before diffing the object.

Ok, whatever 🤷‍♂️

@infostreams First of all, sorry for not finding a solution earlier.
I have done a bit more research, and I think I have found a way to deal with this without causing a large size and performance cost by taking advantage of the preexisting loop. I should be able to release a bug fix that fixes this problem soon.

Awesome! Sorry for having been an ass about this, I could have done that better. Thanks for taking it seriously!

It is not your fault, I was making this lower priority than it should have been, and I did not think of a solution that I should have thought of before.
I have released a new version, 1.1.2, that should have this fixed. If you have any more problems, let me know.