[PATCH 3 of 3 RFC] chgserve: preimport enabled extensions
Jun Wu
quark at fb.com
Mon Oct 3 02:32:47 EDT 2016
This is the first 3 patches of the chg re-arch series. They may look simpler
than expected at first sight, but locally I have 7 more patches, and the
handling of "ui" is still not done yet.
I have chosen these 3 to start the discussion, as they reveal the plan to
some extent, and seem to be most relevant to the next steps.
- Should we hack "hg" / "dispatch" instead so they become aware of chg?
This leads to simpler code but since chg is experimental, I guess the
answer is no for now. But we may move chg to dispatch eventually.
- "chgserve" as an executable, will couple with "hgext/chgserver.py".
With the current direction, "chgserver" will make less sense as an
extension. I'm not sure if moving it out is a good idea or not.
Excerpts from Jun Wu's message of 2016-10-03 07:11:20 +0100:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1475463449 -3600
> # Mon Oct 03 03:57:29 2016 +0100
> # Node ID 6f38a7d259add12c44040535681c4b3ceef0a791
> # Parent 7d106c3386e17746c9b49ab9c788535634b3e8f6
> # Available At https://bitbucket.org/quark-zju/hg-draft
> # hg pull https://bitbucket.org/quark-zju/hg-draft -r 6f38a7d259ad
> chgserve: preimport enabled extensions
>
> This patch pre-imports enabled extensions, so performance improvement is
> visible. It's about 0.01 seconds slower than the old chg, which seems to be
> acceptable.
>
> diff --git a/contrib/chg/chgserve b/contrib/chg/chgserve
> --- a/contrib/chg/chgserve
> +++ b/contrib/chg/chgserve
> @@ -11,4 +11,5 @@ from mercurial import (
> commandserver,
> dispatch,
> + extensions,
> fancyopts,
> ui as uimod,
> @@ -24,4 +25,27 @@ def _confighash(ui):
> return envhash[:12]
>
> +_preimported = {} # {(name, path): mod}
> +
> +def _importext(orig, name, path=None, reportfunc=None):
> + mod = _preimported.get((name, path))
> + if mod:
> + return mod
> + else:
> + return orig(name, path, reportfunc)
> +
> +def _preimportextensions(ui):
> + for name, path in ui.configitems("extensions"):
> + # only enabled extensions are pre-imported - assuming importing an
> + # extension is side-effect free.
> + if path.startswith('!'):
> + continue
> + try:
> + mod = extensions._importext(name, path)
> + except ImportError:
> + pass
> + else:
> + _preimported[(name, path)] = mod
> + ui.debug('chg: preimported %s\n' % name)
> +
> def _startchgservice():
> # patch chgserver's confighash to only hash environment variables
> @@ -35,4 +59,7 @@ def _startchgservice():
> fancyopts.fancyopts(args, commands.table['^serve'][1], opts)
>
> + _preimportextensions(ui)
> + extensions.wrapfunction(extensions, '_importext', _importext)
> +
> service = chgserver.chgunixservice(ui, repo, opts)
> cmdutil.service(opts, initfn=service.init, runfn=service.run)
More information about the Mercurial-devel
mailing list