tests/fakepatchtime.py
author Simon Sapin <simon.sapin@octobus.net>
Tue, 27 Apr 2021 12:42:21 +0200
changeset 47130 04bcba539c96
parent 45957 89a2afe31e82
child 48966 6000f5b25c9b
permissions -rw-r--r--
dirstate-tree: Avoid BTreeMap double-lookup when inserting a dirstate entry The child nodes of a given node in the tree-shaped dirstate are kept in a `BTreeMap` where keys are file names as strings. Finding or inserting a value in the map takes `O(log(n))` string comparisons, which adds up when constructing the tree. The `entry` API allows finding a "spot" in the map that may or may not be occupied and then access that value or insert a new one without doing map lookup again. However the current API is limited in that calling `entry` requires an owned key (and so a memory allocation), even if it ends up not being used in the case where the map already has a value with an equal key. This is still a win, with 4% better end-to-end time for `hg status` measured here with hyperfine: ``` Benchmark #1: ../hg2/hg status -R $REPO --config=experimental.dirstate-tree.in-memory=1 Time (mean ± σ): 1.337 s ± 0.018 s [User: 892.9 ms, System: 437.5 ms] Range (min … max): 1.316 s … 1.373 s 10 runs Benchmark #2: ./hg status -R $REPO --config=experimental.dirstate-tree.in-memory=1 Time (mean ± σ): 1.291 s ± 0.008 s [User: 853.4 ms, System: 431.1 ms] Range (min … max): 1.283 s … 1.309 s 10 runs Summary './hg status -R $REPO --config=experimental.dirstate-tree.in-memory=1' ran 1.04 ± 0.02 times faster than '../hg2/hg status -R $REPO --config=experimental.dirstate-tree.in-memory=1' ``` * ./hg is this revision * ../hg2/hg is its parent * $REPO is an old snapshot of mozilla-central Differential Revision: https://phab.mercurial-scm.org/D10550
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     1
# extension to emulate invoking 'patch.internalpatch()' at the time
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     2
# specified by '[fakepatchtime] fakenow'
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     3
27284
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     4
from __future__ import absolute_import
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     5
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     6
from mercurial import (
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     7
    extensions,
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     8
    patch as patchmod,
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
     9
    registrar,
27284
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
    10
)
36636
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36358
diff changeset
    11
from mercurial.utils import dateutil
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    12
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    13
configtable = {}
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    14
configitem = registrar.configitem(configtable)
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    15
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    16
configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
    17
    b'fakepatchtime',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
    18
    b'fakenow',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
    19
    default=None,
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    20
)
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    21
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    22
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    23
def internalpatch(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    24
    orig,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    25
    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    26
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    27
    patchobj,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    28
    strip,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    29
    prefix=b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    30
    files=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    31
    eolmode=b'strict',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    32
    similarity=0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    33
):
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    34
    if files is None:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    35
        files = set()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    36
    r = orig(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    37
        ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    38
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    39
        patchobj,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    40
        strip,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    41
        prefix=prefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    42
        files=files,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    43
        eolmode=eolmode,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    44
        similarity=similarity,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    45
    )
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    46
36358
9a75619776ca py3: add b'' prefixes in fakepatchtime.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34772
diff changeset
    47
    fakenow = ui.config(b'fakepatchtime', b'fakenow')
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    48
    if fakenow:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    49
        # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    50
        # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
36636
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36358
diff changeset
    51
        fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0]
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    52
        for f in files:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    53
            repo.wvfs.utime(f, (fakenow, fakenow))
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    54
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    55
    return r
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    56
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    57
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    58
def extsetup(ui):
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    59
    extensions.wrapfunction(patchmod, 'internalpatch', internalpatch)