[PATCH 3 of 3 RFC] chgserve: preimport enabled extensions
Jun Wu
quark at fb.com
Mon Oct 3 06:11:20 UTC 2016
# 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