Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was using PHPUnit when a test, which compared two big DOMDocument files, stopped due to the exceeding of the memory limit. I investigated the story, and found that the method which generates the diff for the failed tests is using a dynamic programming-based approach. This algorithm have a quadratic running time, and requires quadratic memory.
If the available time-frame to run the tests is not extremely tight, the memory consumption is a stricter bottleneck.
In this pull request I replaced the old LCS method with a new one based on an algorithm called Hirschberg's algorithm, which also have a quadratic running time, but only uses linear space. The new algorithm is a bit slower (30-40%), but removes the memory bottleneck, thus makes PHPUnit suitable for comparing bigger items.