##// END OF EJS Templates
match: match explicit file using a set...
match: match explicit file using a set The matcher as all the logic to do quick comparison against explicit patterns, however the pattern matcher was shadowing the code using that set and used the compiled regex pattern in all cases, which is quite slow. We restore the usage of the set based matching to boost performance. Building the regexp is still consuming a large amount of time (actually, the majority of the time), which is still silly. Maybe using re2 would help that, but this is a quest for another adventure. Another path to improve this is to have a pattern type dedicated to match the exact path to a file only (not a directory). This pattern could use the set matching only and be skipped in the regex all together. Benchmarks ========== In the following benchmark we are comparing the `hg cat` and `hg files` run time when matching against all files in the repository. They are run: - without the rust extensions - with the standard python engine (so without re2) Performance improvement in this series -------------------------------------- ###### hg files ############################################################### ### mercurial-2018-08-01-zstd-sparse-revlog ### sorted base-changeset: 0.230092 seconds prev-changeset: 0.230069 seconds this-changeset: 0.211425 seconds (-8.36%) ### mercurial-2018-08-01-zstd-sparse-revlog ### shuffled base-changeset: 0.234235 seconds prev-changeset: 0.231165 seconds (-1.38%) this-changeset: 0.212300 seconds (-9.43%) ### pypy-2018-08-01-zstd-sparse-revlog ### sorted base-changeset: 0.613567 seconds prev-changeset: 0.616799 seconds this-changeset: 0.510852 seconds (-16.82%) ### pypy-2018-08-01-zstd-sparse-revlog ### shuffled base-changeset: 0.801880 seconds prev-changeset: 0.616393 seconds (-23.22%) this-changeset: 0.511903 seconds (-36.23%) ### netbeans-2018-08-01-zstd-sparse-revlog ### sorted base-changeset: 21.541828 seconds prev-changeset: 21.586773 seconds this-changeset: 13.648347 seconds (-36.76%) ### netbeans-2018-08-01-zstd-sparse-revlog ### shuffled base-changeset: 172.759857 seconds prev-changeset: 21.908197 seconds (-87.32%) this-changeset: 13.945110 seconds (-91.93%) ### mozilla-central-2018-08-01-zstd-sparse-revlog ### sorted base-changeset: 62.474221 seconds prev-changeset: 61.279490 seconds (-1.22%) this-changeset: 29.529469 seconds (-52.40%) ### mozilla-central-2018-08-01-zstd-sparse-revlog ### shuffled base-changeset: 1364.180218 seconds prev-changeset: 62.473549 seconds (-95.40%) this-changeset: 30.625249 seconds (-97.75%) ###### hg cat ################################################################# ### mercurial-2018-08-01-zstd-sparse-revlog ### sorted base-changeset: 0.764407 seconds prev-changeset: 0.763883 seconds this-changeset: 0.737326 seconds (-3.68%) ### mercurial-2018-08-01-zstd-sparse-revlog ### shuffled base-changeset: 0.768924 seconds prev-changeset: 0.765848 seconds this-changeset: 0.174d0b seconds (-4.44%) ### pypy-2018-08-01-zstd-sparse-revlog ### sorted base-changeset: 2.065220 seconds prev-changeset: 2.070498 seconds this-changeset: 1.939482 seconds (-6.08%) ### pypy-2018-08-01-zstd-sparse-revlog ### shuffled base-changeset: 2.276388 seconds prev-changeset: 2.069197 seconds (-9.15%) this-changeset: 1.931746 seconds (-15.19%) ### netbeans-2018-08-01-zstd-sparse-revlog ### sorted base-changeset: 40.967983 seconds prev-changeset: 41.392423 seconds this-changeset: 32.181681 seconds (-22.20%) ### netbeans-2018-08-01-zstd-sparse-revlog ### shuffled base-changeset: 216.388709 seconds prev-changeset: 41.648689 seconds (-80.88%) this-changeset: 32.580817 seconds (-85.04%) ### mozilla-central-2018-08-01-zstd-sparse-revlog ### sorted base-changeset: 105.228510 seconds prev-changeset: 103.315670 seconds (-1.23%) this-changeset: 69.416118 seconds (-33.64%) ### mozilla-central-2018-08-01-zstd-sparse-revlog ### shuffled base-changeset: 1448.722784 seconds prev-changeset: 104.369358 seconds (-92.80%) this-changeset: 70.554789 seconds (-95.13%) Different way to list the same data with this revision ------------------------------------------------------ ###### hg files ############################################################### ### mercurial-2018-08-01-zstd-sparse-revlog root: 0.119182 seconds glob: 0.120697 seconds (+1.27%) sorted: 0.211425 seconds (+77.40%) shuffled: 0.212300 seconds (+78.13%) ### pypy-2018-08-01-zstd-sparse-revlog root: 0.121986 seconds glob: 0.124822 seconds (+2.32%) sorted: 0.510852 seconds (+318.78%) shuffled: 0.511903 seconds (+319.64%) ### netbeans-2018-08-01-zstd-sparse-revlog root: 0.173984 seconds glob: 0.227203 seconds (+30.59%) sorted: 13.648347 seconds (+7744.59%) shuffled: 13.945110 seconds (+7915.16%) ### mozilla-central-2018-08-01-zstd-sparse-revlog root: 0.366463 seconds glob: 0.491030 seconds (+33.99%) sorted: 29.529469 seconds (+7957.96%) shuffled: 30.625249 seconds (+8256.97%) ###### hg cat ################################################################# ### mercurial-2018-08-01-zstd-sparse-revlog glob: 0.647471 seconds root: 0.643120 seconds shuffled: 0.174d0b seconds (+13.92%) sorted: 0.737326 seconds (+13.88%) ### mozilla-central-2018-08-01-zstd-sparse-revlog glob: 40.596983 seconds root: 40.129136 seconds shuffled: 70.554789 seconds (+73.79%) sorted: 69.416118 seconds (+70.99%) ### netbeans-2018-08-01-zstd-sparse-revlog glob: 18.777924 seconds root: 18.613905 seconds shuffled: 32.580817 seconds (+73.51%) sorted: 32.181681 seconds (+71.38%) ### pypy-2018-08-01-zstd-sparse-revlog glob: 1.555319 seconds root: 1.536534 seconds shuffled: 1.931746 seconds (+24.20%) sorted: 1.939482 seconds (+24.70%)

File last commit:

r49801:642e31cb default
r51286:81c7d04f stable
Show More
httpconnection.py
138 lines | 4.2 KiB | text/x-python | PythonLexer
Augie Fackler
url: use new http support if requested by the user...
r14244 # httpconnection.py - urllib2 handler for new http support
#
Raphaël Gomès
contributor: change mentions of mpm to olivia...
r47575 # Copyright 2005, 2006, 2007, 2008 Olivia Mackall <olivia@selenic.com>
Augie Fackler
url: use new http support if requested by the user...
r14244 # Copyright 2006, 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br>
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
# Copyright 2011 Google, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
Gregory Szorc
httpconnection: use absolute_import
r27521
import os
Augie Fackler
url: use new http support if requested by the user...
r14244
Gregory Szorc
httpconnection: use absolute_import
r27521 from .i18n import _
Gregory Szorc
py3: manually import pycompat.open into files that need it...
r43355 from .pycompat import open
Gregory Szorc
httpconnection: use absolute_import
r27521 from . import (
Augie Fackler
httpconnection: convert url to bytes in readauthforuri...
r36669 pycompat,
Gregory Szorc
httpconnection: use absolute_import
r27521 util,
)
urlutil: extract `url` related code from `util` into the new module...
r47669 from .utils import (
urlutil,
)
Augie Fackler
url: use new http support if requested by the user...
r14244
timeless
pycompat: switch to util.urlreq/util.urlerr for py3 compat
r28883 urlerr = util.urlerr
urlreq = util.urlreq
Augie Fackler
url: use new http support if requested by the user...
r14244 # moved here from url.py to avoid a cycle
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class httpsendfile:
Augie Fackler
url: use new http support if requested by the user...
r14244 """This is a wrapper around the objects returned by python's "open".
Mads Kiilerich
http: handle push of bundles > 2 GB again (issue3017)...
r15152 Its purpose is to send file-like objects via HTTP.
It do however not define a __len__ attribute because the length
might be more than Py_ssize_t can handle.
Augie Fackler
url: use new http support if requested by the user...
r14244 """
def __init__(self, ui, *args, **kwargs):
self.ui = ui
self._data = open(*args, **kwargs)
self.seek = self._data.seek
self.close = self._data.close
self.write = self._data.write
Mads Kiilerich
http: handle push of bundles > 2 GB again (issue3017)...
r15152 self.length = os.fstat(self._data.fileno()).st_size
Augie Fackler
url: use new http support if requested by the user...
r14244 self._pos = 0
Matt Harbison
httpconnection: allow `httpsendfile` subclasses to suppress the progressbar...
r44780 self._progress = self._makeprogress()
def _makeprogress(self):
Augie Fackler
url: use new http support if requested by the user...
r14244 # We pass double the max for total because we currently have
# to send the bundle twice in the case of a server that
# requires authentication. Since we can't know until we try
# once whether authentication will be required, just lie to
# the user and maybe the push succeeds suddenly at 50%.
Matt Harbison
httpconnection: allow `httpsendfile` subclasses to suppress the progressbar...
r44780 return self.ui.makeprogress(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'sending'), unit=_(b'kb'), total=(self.length // 1024 * 2)
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 )
Martin von Zweigbergk
httpconnection: use progress helper...
r38412
def read(self, *args, **kwargs):
ret = self._data.read(*args, **kwargs)
if not ret:
self._progress.complete()
return ret
self._pos += len(ret)
self._progress.update(self._pos // 1024)
Augie Fackler
url: use new http support if requested by the user...
r14244 return ret
Mads Kiilerich
largefiles: use context for file closing...
r30142 def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.close()
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345
Augie Fackler
url: use new http support if requested by the user...
r14244 # moved here from url.py to avoid a cycle
Patrick Mezard
http: pass user to readauthforuri() (fix 4a43e23b8c55)...
r15025 def readauthforuri(ui, uri, user):
Augie Fackler
httpconnection: convert url to bytes in readauthforuri...
r36669 uri = pycompat.bytesurl(uri)
Augie Fackler
url: use new http support if requested by the user...
r14244 # Read configuration
Gregory Szorc
httpconnection: rename config to groups...
r31300 groups = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for key, val in ui.configitems(b'auth'):
if key in (b'cookiefile',):
Gregory Szorc
httpconnection: allow a global auth.cookiefile config entry...
r31935 continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'.' not in key:
ui.warn(_(b"ignoring invalid [auth] key '%s'\n") % key)
Augie Fackler
url: use new http support if requested by the user...
r14244 continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 group, setting = key.rsplit(b'.', 1)
Gregory Szorc
httpconnection: rename config to groups...
r31300 gdict = groups.setdefault(group, {})
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if setting in (b'username', b'cert', b'key'):
Augie Fackler
url: use new http support if requested by the user...
r14244 val = util.expandpath(val)
gdict[setting] = val
# Find the best match
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 scheme, hostpath = uri.split(b'://', 1)
Patrick Mezard
hgweb: do not ignore [auth] if url has a username (issue2822)...
r15005 bestuser = None
Augie Fackler
url: use new http support if requested by the user...
r14244 bestlen = 0
bestauth = None
Gregory Szorc
global: bulk replace simple pycompat.iteritems(x) with x.items()...
r49768 for group, auth in groups.items():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if user and user != auth.get(b'username', user):
Patrick Mezard
hgweb: do not ignore [auth] if url has a username (issue2822)...
r15005 # If a username was set in the URI, the entry username
# must either match it or be unset
continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 prefix = auth.get(b'prefix')
Augie Fackler
url: use new http support if requested by the user...
r14244 if not prefix:
continue
Matt Harbison
http: allow 'auth.prefix' to have a username consistent with the URI...
r40699
urlutil: extract `url` related code from `util` into the new module...
r47669 prefixurl = urlutil.url(prefix)
Matt Harbison
http: allow 'auth.prefix' to have a username consistent with the URI...
r40699 if prefixurl.user and prefixurl.user != user:
# If a username was set in the prefix, it must match the username in
# the URI.
continue
# The URI passed in has been stripped of credentials, so erase the user
# here to allow simpler matching.
prefixurl.user = None
prefix = bytes(prefixurl)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 p = prefix.split(b'://', 1)
Augie Fackler
url: use new http support if requested by the user...
r14244 if len(p) > 1:
schemes, prefix = [p[0]], p[1]
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 schemes = (auth.get(b'schemes') or b'https').split()
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 if (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (prefix == b'*' or hostpath.startswith(prefix))
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 and (
len(prefix) > bestlen
or (
len(prefix) == bestlen
and not bestuser
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 and b'username' in auth
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 )
)
and scheme in schemes
):
Augie Fackler
url: use new http support if requested by the user...
r14244 bestlen = len(prefix)
bestauth = group, auth
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 bestuser = auth.get(b'username')
Patrick Mezard
hgweb: do not ignore [auth] if url has a username (issue2822)...
r15005 if user and not bestuser:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 auth[b'username'] = user
Augie Fackler
url: use new http support if requested by the user...
r14244 return bestauth