tests/test-hgwebdir-paths.py
author Martijn Pieters <mj@zopatista.com>
Tue, 31 Jul 2018 19:37:54 +0200
changeset 38781 0a57945aaf7f
parent 37879 81455f482478
child 43076 2372284d9457
permissions -rw-r--r--
manifest: persist the manifestfulltext cache Reconstructing the manifest from the revlog takes time, so much so that there already is a LRU cache to avoid having to load a manifest multiple times. This patch persists that LRU cache in the .hg/cache directory, so we can re-use this cache across hg commands. Commit benchmark (run on Macos 10.13 on a 2017-model Macbook Pro with Core i7 2.9GHz and flash drive), testing without and with patch run 5 times, baseline is r2a227782e754: * committing to an existing file, against the mozilla-central repository. Baseline real time average 1.9692, with patch 1.3786. A new debugcommand "hg debugmanifestfulltextcache" lets you inspect the cache, clear it, or add specific manifest nodeids to it. When calling repo.updatecaches(), the manifest(s) for the working copy parents are added to the cache. The hg perfmanifest command has an additional --clear-disk switch to clear this cache when testing manifest loading performance. Using this command to test performance on the firefox repository for revision f947d902ed91, whose manifest has a delta chain length of 60540, we see: $ hg perfmanifest f947d902ed91 --clear-disk ! wall 0.972253 comb 0.970000 user 0.850000 sys 0.120000 (best of 10) $ hg debugmanifestfulltextcache -a `hg log --debug -r f947d902ed91 | grep manifest | cut -d: -f3` Cache contains 1 manifest entries, in order of most to least recent: id: 0294517df4aad07c70701db43bc7ff24c3ce7dbc, size 25.6 MB Total cache data size 25.6 MB, on-disk 0 bytes $ hg perfmanifest f947d902ed91 ! wall 0.036748 comb 0.040000 user 0.020000 sys 0.020000 (best of 100) Worst-case scenario: a manifest text loaded from a single delta; in the firefox repository manifest node 9a1246ff762e is the chain base for the manifest attached to revision f947d902ed91. Loading this from a full cache file is just as fast as without the cache; the extra node ids ensure a big full cache: $ for node in 9a1246ff762e 1a1922c14a3e 54a31d11a36a 0294517df4aa; do > hgd debugmanifestfulltextcache -a $node > /dev/null > done $ hgd perfmanifest -m 9a1246ff762e ! wall 0.077513 comb 0.080000 user 0.030000 sys 0.050000 (best of 100) $ hgd perfmanifest -m 9a1246ff762e --clear-disk ! wall 0.078547 comb 0.080000 user 0.070000 sys 0.010000 (best of 100)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28932
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     1
from __future__ import absolute_import
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     2
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
     3
import os
28932
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     4
from mercurial import (
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     5
    hg,
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     6
    ui as uimod,
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     7
)
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     8
from mercurial.hgweb import (
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     9
    hgwebdir_mod,
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
    10
)
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
    11
hgwebdir = hgwebdir_mod.hgwebdir
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    12
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    13
os.mkdir(b'webdir')
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    14
os.chdir(b'webdir')
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    15
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    16
webdir = os.path.realpath(b'.')
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    17
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28932
diff changeset
    18
u = uimod.ui.load()
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    19
hg.repository(u, b'a', create=1)
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    20
hg.repository(u, b'b', create=1)
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    21
os.chdir(b'b')
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    22
hg.repository(u, b'd', create=1)
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    23
os.chdir(b'..')
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    24
hg.repository(u, b'c', create=1)
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    25
os.chdir(b'..')
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    26
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    27
paths = {b't/a/': b'%s/a' % webdir,
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    28
         b'b': b'%s/b' % webdir,
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    29
         b'coll': b'%s/*' % webdir,
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    30
         b'rcoll': b'%s/**' % webdir}
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    31
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    32
config = os.path.join(webdir, b'hgwebdir.conf')
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    33
configfile = open(config, 'wb')
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    34
configfile.write(b'[paths]\n')
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    35
for k, v in paths.items():
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    36
    configfile.write(b'%s = %s\n' % (k, v))
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    37
configfile.close()
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    38
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    39
confwd = hgwebdir(config)
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    40
dictwd = hgwebdir(paths)
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    41
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    42
assert len(confwd.repos) == len(dictwd.repos), 'different numbers'
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    43
assert len(confwd.repos) == 9, 'expected 9 repos, found %d' % len(confwd.repos)
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    44
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    45
found = dict(confwd.repos)
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    46
for key, path in dictwd.repos:
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    47
    assert key in found, 'repository %s was not found' % key
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    48
    assert found[key] == path, 'different paths for repo %s' % key