py3: speed up simplemerge

Summary:
One user reports very very slow rebase (tens of minutes and running). The
commit is not very large. Python 2 can complete the rebase in 6 seconds.
I tracked it down to this code path. Making the change makes Python 3
rebase fast too (< 10 seconds). I haven't tracked down exactly why Python
3 is slow yet (maybe N^2 a += b)?

Some numbers about the slow merge:

  ipdb> p len(m3.atext)
  17984924
  ipdb> p len(m3.btext)
  17948110
  ipdb> p len(m3.a)
  613353
  ipdb> p len(m3.b)
  612129
  ipdb> p len(m3.base)
  612135

Reviewed By: singhsrb

Differential Revision: D23441221

fbshipit-source-id: 14b725439f4ecd3352edca512cdde32958b2ce29
This commit is contained in:
Jun Wu 2020-09-01 20:30:38 -07:00 committed by Facebook GitHub Bot
parent 2d02d3b0f7
commit d8225764a5

View File

@ -473,14 +473,11 @@ def simplemerge(ui, localctx, basectx, otherctx, **opts):
extrakwargs["name_base"] = name_base
extrakwargs["minimize"] = False
mergedtext = b""
for line in m3.merge_lines(name_a=name_a, name_b=name_b, **extrakwargs):
if opts.get("print"):
ui.fout.write(line)
else:
mergedtext += line
if not opts.get("print"):
lines = list(m3.merge_lines(name_a=name_a, name_b=name_b, **extrakwargs))
mergedtext = b"".join(lines)
if opts.get("print"):
ui.fout.write(mergedtext)
else:
# HACK(phillco): We need to call ``workingflags()`` if ``localctx`` is
# a workingfilectx (see workingfilectx.workingflags).
flags = getattr(localctx, "workingflags", localctx.flags)()