This is an archive of the discontinued Mercurial Phabricator instance.

xdiff: reduce indent heuristic overhead
ClosedPublic

Authored by quark on Mar 3 2018, 3:07 PM.

Details

Summary

Adds some threshold to avoid expensive cases, like:

#!python
open('a', 'w').write(" \n" * 1000000)
open('b', 'w').write(" \n" * 1000001)

The indent heuristic is O(N * 20) (N = 1000000) for the above case, and
makes diff much slower.

Before this patch (system git 2.14.2):

git diff --no-indent-heuristic a b  0.21s user 0.03s system 100% cpu 0.239 total
git diff --indent-heuristic a b     0.77s user 0.02s system 99% cpu 0.785 total

After this patch (git 2fc74f41, with xdiffi.c patched):

# with the changed xdiffi.c
git diff --indent-heuristic a b      0.16s user 0.01s system 90% cpu 0.188 total
git diff --no-indent-heuristic a b   0.18s user 0.01s system 99% cpu 0.192 total

Now turning on indent-heuristic has no visible impact on performance.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

quark created this revision.Mar 3 2018, 3:07 PM
quark updated this revision to Diff 6475.Mar 3 2018, 3:30 PM
indygreg accepted this revision.Mar 3 2018, 4:09 PM
This revision is now accepted and ready to land.Mar 3 2018, 4:09 PM
durin42 accepted this revision.Mar 3 2018, 6:12 PM
This revision was automatically updated to reflect the committed changes.