[PATCH 8 of 8 demandimport-py3] python3: allow hgloader to work with lazy loaders

Gregory Szorc gregory.szorc at gmail.com
Sun May 21 21:26:53 EDT 2017


On Sun, May 21, 2017 at 1:48 PM, Siddharth Agarwal <sid0 at fb.com> wrote:

> # HG changeset patch
> # User Siddharth Agarwal <sid0 at fb.com>
> # Date 1495398377 25200
> #      Sun May 21 13:26:17 2017 -0700
> # Node ID 902d8e08f7e5bc6114e2fd9285be6ef75225da9e
> # Parent  1bf07f6a0c323a4a842d7e76d14e4e893a2b68ca
> python3: allow hgloader to work with lazy loaders
>
> Don't clobber the loader returned from find_spec.
>
> This brings `hg version` down from 0.27 seconds to 0.17.
>

Out of curiosity, is this with HGRCPATH=? On my machine, current `hg
version` on 3.6.0 on Linux on any i7-6700K is ~130ms. ~25ms with Python 2
(~60ms with demand import disabled). I suspect your machine is either much
slower or loading a bunch of extensions.


>
> diff --git a/mercurial/__init__.py b/mercurial/__init__.py
> --- a/mercurial/__init__.py
> +++ b/mercurial/__init__.py
> @@ -53,7 +53,14 @@ if sys.version_info[0] >= 3:
>
>              # TODO need to support loaders from alternate specs, like zip
>              # loaders.
> -            spec.loader = hgloader(spec.name, spec.origin)
> +            loader = hgloader(spec.name, spec.origin)
> +            # Can't use util.safehasattr here because that would require
> +            # importing util, and we're in import code.
> +            if hasattr(spec.loader, 'loader'): # hasattr-py3-only
> +                # This is a nested loader (maybe a lazy loader?)
> +                spec.loader.loader = loader
> +            else:
> +                spec.loader = loader
>              return spec
>
>      def replacetokens(tokens, fullname):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170521/5c7f2001/attachment.html>


More information about the Mercurial-devel mailing list