[PATCH 3 of 5 RFC] dirstate: make dirstate._join a bit faster on posix

Yuya Nishihara yuya at tcha.org
Fri Aug 18 09:19:37 EDT 2017


On Fri, 18 Aug 2017 08:13:05 +0000, Kostia Balytskyi wrote:
> > -----Original Message-----
> > From: Yuya Nishihara [mailto:youjah at gmail.com] On Behalf Of Yuya
> > Nishihara
> > Sent: Monday, 14 August, 2017 03:51
> > To: Kostia Balytskyi <ikostia at fb.com>
> > Cc: mercurial-devel at mercurial-scm.org
> > Subject: Re: [PATCH 3 of 5 RFC] dirstate: make dirstate._join a bit faster on
> > posix
> > 
> > On Sat, 12 Aug 2017 01:22:58 -0700, Kostia Balytskyi wrote:
> > > # HG changeset patch
> > > # User Kostia Balytskyi <ikostia at fb.com> # Date 1502522493 25200
> > > #      Sat Aug 12 00:21:33 2017 -0700
> > > # Node ID bac7b1ae4a0c998c57cea5eac51af66853779918
> > > # Parent  a1c8f310a66ada40697c824f4621bb54c757e9fa
> > > dirstate: make dirstate._join a bit faster on posix
> > >
> > > This is a micro-optimization, suggested by @quark for one of the
> > > previous patches. It is safe to land the series without this micro-
> > optimization.
> > >
> > > diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
> > > --- a/mercurial/dirstate.py
> > > +++ b/mercurial/dirstate.py
> > > @@ -99,6 +99,9 @@ class dirstate(object):
> > >          # for consistent view between _pl() and _read() invocations
> > >          self._pendingmode = None
> > >
> > > +        if pycompat.osname != 'nt':
> > > +            self._join = self._join_posix
> > 
> > Assigning a bound method to self creates a reference cycle. nt/posix can be
> > selected statically.
> 
> I will resolve the reference cycle in the next iteration, but IIUC, 'selected statically' necessarily involves another stack frame in call stack every time self._join is called. That's what I would like to avoid, therefore I prefer assigning it in the __init__.

I meant this could be:

    class dirstate:
        if osname == 'nt':
            def _join(self):
                ...
        else:
            def _join(self):
               ... fast path ...

self._join is aliased before running hot loops, so we wouldn't have to care
about the cost of the method resolution.

FWIW, I'm not super familiar with Windows stuff, but the direction of this
patch seems nice, thanks.


More information about the Mercurial-devel mailing list