Patchwork [STABLE] revset: avoid O(n) lookup of invalid revision in rev()

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 23, 2014, 1:28 p.m.
Message ID <42c36ac3d11ea9ff7072.1414070916@mimosa>
Download mbox | patch
Permalink /patch/6444/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 23, 2014, 1:28 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1414068817 -32400
#      Thu Oct 23 21:53:37 2014 +0900
# Branch stable
# Node ID 42c36ac3d11ea9ff707279737538463f7877be04
# Parent  d583f1cfca9670946d7e315df4d0a0efccb7a612
revset: avoid O(n) lookup of invalid revision in rev()

ba89f7b542c9 was not the final version of that patch.  It was really slow
because `l not in repo.changelog` iterates revisions up to `l`.  Instead,
rev() should utilize spanset.__contains__().

revset #0: rev(210000)
0) wall 0.000039 comb 0.000000 user 0.000000 sys 0.000000 (best of 67978)
1) wall 0.002721 comb 0.000000 user 0.000000 sys 0.000000 (best of 1055)
2) wall 0.000059 comb 0.000000 user 0.000000 sys 0.000000 (best of 45599)
(0: 3.2-rc, 1: ba89f7b542c9, 2: this patch)

Note that the benchmark result described in ba89f7b542c9 is wrong because
it is the one of the initial version.
David Soria Parra - Oct. 23, 2014, 3:30 p.m.
Yuya Nishihara <yuya@tcha.org> writes:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1414068817 -32400
> #      Thu Oct 23 21:53:37 2014 +0900
> # Branch stable
> # Node ID 42c36ac3d11ea9ff707279737538463f7877be04
> # Parent  d583f1cfca9670946d7e315df4d0a0efccb7a612
> revset: avoid O(n) lookup of invalid revision in rev()
>

Queued for clowncopter. Thank you.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1351,7 +1351,7 @@  def rev(repo, subset, x):
     except (TypeError, ValueError):
         # i18n: "rev" is a keyword
         raise error.ParseError(_("rev expects a number"))
-    if l not in repo.changelog:
+    if l not in fullreposet(repo):
         return baseset()
     return subset & baseset([l])