Mercurial > public > mercurial-scm > hg
annotate mercurial/node.py @ 48178:f12a19d03d2c
fix: reduce number of tool executions
By grouping together (path, ctx) pairs according to the inputs they would
provide to fixer tools, we can deduplicate executions of fixer tools to
significantly reduce the amount of time spent running slow tools.
This change does not handle clean files in the working copy, which could still
be deduplicated against the files in the checked out commit. It's a little
harder to do that because the filerev is not available in the workingfilectx
(and it doesn't exist for added files).
Anecdotally, this change makes some real uses cases at Google 10x faster. I
think we were originally hesitant to do this because the benefits weren't
obvious, and implementing it efficiently is kind of tricky. If we simply
memoized the formatter execution function, we would be keeping tons of file
content in memory.
Also included is a regression test for a corner case that I broke with my first
attempt at optimizing this code.
Differential Revision: https://phab.mercurial-scm.org/D11280
author | Danny Hooper <hooper@google.com> |
---|---|
date | Thu, 02 Sep 2021 14:08:45 -0700 |
parents | d4ba4d51f85f |
children | 6000f5b25c9b |
rev | line source |
---|---|
8226
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
1 # node.py - basic nodeid manipulation for mercurial |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
2 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46780
diff
changeset
|
3 # Copyright 2005, 2006 Olivia Mackall <olivia@selenic.com> |
8226
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
4 # |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
1089 | 7 |
25962
738314da6c75
node: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25737
diff
changeset
|
8 from __future__ import absolute_import |
738314da6c75
node: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25737
diff
changeset
|
9 |
3877
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3578
diff
changeset
|
10 import binascii |
1089 | 11 |
26980
18f50b8cbf1e
node: add 'nullhex', hex-encoded nullid
Siddharth Agarwal <sid0@fb.com>
parents:
25962
diff
changeset
|
12 # This ugly style has a noticeable effect in manifest parsing |
18f50b8cbf1e
node: add 'nullhex', hex-encoded nullid
Siddharth Agarwal <sid0@fb.com>
parents:
25962
diff
changeset
|
13 hex = binascii.hexlify |
36238
f574cc00831a
node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents:
32684
diff
changeset
|
14 # Adapt to Python 3 API changes. If this ends up showing up in |
f574cc00831a
node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents:
32684
diff
changeset
|
15 # profiles, we can use this version only on Python 3, and forward |
f574cc00831a
node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents:
32684
diff
changeset
|
16 # binascii.unhexlify like we used to on Python 2. |
f574cc00831a
node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents:
32684
diff
changeset
|
17 def bin(s): |
f574cc00831a
node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents:
32684
diff
changeset
|
18 try: |
f574cc00831a
node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents:
32684
diff
changeset
|
19 return binascii.unhexlify(s) |
f574cc00831a
node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents:
32684
diff
changeset
|
20 except binascii.Error as e: |
f574cc00831a
node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents:
32684
diff
changeset
|
21 raise TypeError(e) |
26980
18f50b8cbf1e
node: add 'nullhex', hex-encoded nullid
Siddharth Agarwal <sid0@fb.com>
parents:
25962
diff
changeset
|
22 |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
39195
diff
changeset
|
23 |
46780
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
24 def short(node): |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
25 return hex(node[:6]) |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
26 |
1089 | 27 |
46780
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
28 nullrev = -1 |
30360
0298a07f64d9
dirstate: change placeholder hash length to 20 bytes
Durham Goode <durham@fb.com>
parents:
28585
diff
changeset
|
29 |
46780
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
30 # pseudo identifier for working directory |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
31 # (experimental, so don't add too many dependencies on it) |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
39195
diff
changeset
|
32 wdirrev = 0x7FFFFFFF |
25737
1a5211f2f87f
node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents:
10263
diff
changeset
|
33 |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
39195
diff
changeset
|
34 |
46780
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
35 class sha1nodeconstants(object): |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
36 nodelen = 20 |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
37 |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
38 # In hex, this is '0000000000000000000000000000000000000000' |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
39 nullid = b"\0" * nodelen |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
40 nullhex = hex(nullid) |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
41 |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
42 # Phony node value to stand-in for new files in some uses of |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
43 # manifests. |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
44 # In hex, this is '2121212121212121212121212121212121212121' |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
45 newnodeid = b'!!!!!!!!!!!!!!!!!!!!' |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
46 # In hex, this is '3030303030303030303030303030306164646564' |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
47 addednodeid = b'000000000000000added' |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
48 # In hex, this is '3030303030303030303030306d6f646966696564' |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
49 modifiednodeid = b'000000000000modified' |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
50 |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
51 wdirfilenodeids = {newnodeid, addednodeid, modifiednodeid} |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
52 |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
53 # pseudo identifier for working directory |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
54 # (experimental, so don't add too many dependencies on it) |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
55 # In hex, this is 'ffffffffffffffffffffffffffffffffffffffff' |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
56 wdirid = b"\xff" * nodelen |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
57 wdirhex = hex(wdirid) |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
58 |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
59 |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
60 # legacy starting point for porting modules |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
61 nullid = sha1nodeconstants.nullid |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
62 nullhex = sha1nodeconstants.nullhex |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
63 newnodeid = sha1nodeconstants.newnodeid |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
64 addednodeid = sha1nodeconstants.addednodeid |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
65 modifiednodeid = sha1nodeconstants.modifiednodeid |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
66 wdirfilenodeids = sha1nodeconstants.wdirfilenodeids |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
67 wdirid = sha1nodeconstants.wdirid |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
43077
diff
changeset
|
68 wdirhex = sha1nodeconstants.wdirhex |