comparison mercurial/revset.py @ 26305:ade5c488d622

revset: remove existence check from min() and max() min() and max() would first do an existence check. Unfortunately existence checks can be slow in certain situations (like if the smartset is a list, and quickly iterable in both ascending and descending directions, then doing an existence check will start from the bottom, even if you want to check the max()). The fix is to not do the check, and just handle the error if it happens. In a large repo, this speeds up: hg log -r 'max(parents(. + .^) - (. + .^) & ::master)' from 3.5s to 0.85s. That revset is contrived and just for testing. In our real case we used 'bundle()' in place of '. + .^' Interesting perf numbers for the revset benchmarks: max(draft() and ::tip) => 0.027s to 0.0005s max(author(lmoscovicz)) => 2.48s to 0.57s min doesn't show any perf changes, but changing it as well will prevent a perf regression in my next patch. Result from revset benchmark revset #0: draft() and ::tip min max 0) 0.001971 0.001991 1) 0.001965 0.000428 21% revset #1: ::tip and draft() min max 0) 0.002017 0.001912 1) 0.001896 94% 0.000421 22% revset #2: author(lmoscovicz) min max 0) 1.049033 1.358913 1) 1.042508 0.319824 23% revset #3: author(lmoscovicz) or author(mpm) min max 0) 1.042512 1.367432 1) 1.019750 0.327750 23% revset #4: author(mpm) or author(lmoscovicz) min max 0) 1.050135 0.324924 1) 1.070698 0.319913 revset #5: roots((tip~100::) - (tip~100::tip)) min max 0) 0.000671 0.001018 1) 0.000605 90% 0.000946 92% revset #6: roots((0::) - (0::tip)) min max 0) 0.149714 0.152369 1) 0.098677 65% 0.100374 65% revset #7: (20000::) - (20000) min max 0) 0.051019 0.042747 1) 0.035586 69% 0.016267 38%
author Durham Goode <durham@fb.com>
date Sun, 20 Sep 2015 19:27:53 -0700
parents bca60842e22d
children d157e1f18e3f
comparison
equal deleted inserted replaced
26304:bca60842e22d 26305:ade5c488d622
1385 def maxrev(repo, subset, x): 1385 def maxrev(repo, subset, x):
1386 """``max(set)`` 1386 """``max(set)``
1387 Changeset with highest revision number in set. 1387 Changeset with highest revision number in set.
1388 """ 1388 """
1389 os = getset(repo, fullreposet(repo), x) 1389 os = getset(repo, fullreposet(repo), x)
1390 if os: 1390 try:
1391 m = os.max() 1391 m = os.max()
1392 if m in subset: 1392 if m in subset:
1393 return baseset([m]) 1393 return baseset([m])
1394 except ValueError:
1395 # os.max() throws a ValueError when the collection is empty.
1396 # Same as python's max().
1397 pass
1394 return baseset() 1398 return baseset()
1395 1399
1396 def merge(repo, subset, x): 1400 def merge(repo, subset, x):
1397 """``merge()`` 1401 """``merge()``
1398 Changeset is a merge changeset. 1402 Changeset is a merge changeset.
1424 def minrev(repo, subset, x): 1428 def minrev(repo, subset, x):
1425 """``min(set)`` 1429 """``min(set)``
1426 Changeset with lowest revision number in set. 1430 Changeset with lowest revision number in set.
1427 """ 1431 """
1428 os = getset(repo, fullreposet(repo), x) 1432 os = getset(repo, fullreposet(repo), x)
1429 if os: 1433 try:
1430 m = os.min() 1434 m = os.min()
1431 if m in subset: 1435 if m in subset:
1432 return baseset([m]) 1436 return baseset([m])
1437 except ValueError:
1438 # os.min() throws a ValueError when the collection is empty.
1439 # Same as python's min().
1440 pass
1433 return baseset() 1441 return baseset()
1434 1442
1435 def modifies(repo, subset, x): 1443 def modifies(repo, subset, x):
1436 """``modifies(pattern)`` 1444 """``modifies(pattern)``
1437 Changesets modifying files matched by pattern. 1445 Changesets modifying files matched by pattern.