diff.rs icon indicating copy to clipboard operation
diff.rs copied to clipboard

Big allocation for a small diff

Open aminya opened this issue 1 year ago • 2 comments

It seems diff-rs allocates a big vector for diffing a small object resulting in out-of-memory

This was discussed in this issue as well https://github.com/rust-pretty-assertions/rust-pretty-assertions/issues/124

https://github.com/utkarshkukreti/diff.rs/blob/0.1.13/src/lib.rs?rgh-link-date=2024-01-31T21%3A37%3A48Z#L150

aminya avatar Jan 31 '24 23:01 aminya

This is because the current algorithm uses O(NM) memory. I've been working on adding a Myers diff implementation (#1) for the last 2 days which would use linear memory and in many cases much less time. I hope to push an implementation on a branch very soon. I will comment when it's up.

utkarshkukreti avatar Feb 03 '24 08:02 utkarshkukreti

I pushed an implementation in the myers branch. Can you test it (point the dependency to this git repo branch = "myers" and change diff::chars to diff::myers::chars) and see if it's fast enough now? The memory usage should be linear now, not quadratic.

utkarshkukreti avatar Feb 04 '24 07:02 utkarshkukreti