filectx: strange performance behavior

Marc Strapetz marc.strapetz at syntevo.com
Fri May 8 18:19:03 UTC 2015


As part of an extension, I'm using following code which takes several 
seconds to execute for a large repository (e.g. setup.py of the 
Mercurial repository):

   filectx = repo['.'][path]
   filectxs = []
   for ctx in filectx.ancestors():
     filectxs.append(ctx)

   # this loop takes a long time
   for ctx in filectxs:
     ui.write(str(ctx.rev()) + '\n')

Interestingly, rewriting the loop to the following code gives results 
almost instantly:

   filectx = repo['.'][path]

   # this loop executes almost instantly
   for ctx in filectx.ancestors():
     ui.write(str(ctx.rev()) + '\n')

Also, when adding an additional rev(), the original loop becomes fast:

   filectx = repo['.'][path]
   filectxs = []
   for ctx in filectx.ancestors():
     ctx.rev() # <-- this makes the loop fast
     filectxs.append(ctx)

   # now the loop executes almost instantly
   for ctx in filectxs:
     ui.write(str(ctx.rev()) + '\n')

Probably this is expected, but my Mercurial/Python knowledge is too 
limited to understand that ... so any hints are appreciated :)

-Marc







More information about the Mercurial-devel mailing list