godebug
godebug copied to clipboard
diff.Diff optimization if one input is empty.
https://github.com/kylelemons/godebug/blob/e693023230a4a8be4e28c9bd02f467b0534ac08b/diff/diff.go#L37-L40
It seems if one input of Diff is empty, then the algorithm uses O(N^2) space, where N is the size of the other input.
The result is I see out of memory error if I diff an empty chunk with a non-empty chunk.
It'll be a good improvement if we can just do an empty check before calling the Diff algorithm. And generating diffstring in such case should not be very hard.
Clarify: In this case, I'm calling pretty.Compare(a, b) where a is an empty Struct (zero value), where b is not.