grep: reuse the first "util.binary()" result for efficiency
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Sat, 15 Feb 2014 19:52:36 +0900
changeset 20836 a8b4541bb961
parent 20835 0e8417131a29
child 20837 191a0ae37767
grep: reuse the first "util.binary()" result for efficiency Before this patch, to check whether the file in the specified revision is binary or not, "util.binary()" is invoked via internal function "binary()" of "hg grep" once per a line of "hg grep" output, even though binary-ness is not changed in the same file. This patch reuses the first "util.binary()" invocation result by annotating internal function "binary()" with "@util.cachefunc". Performance improvement measured by "hgperf grep -r 88d8e568add1 vfs mercurial/scmutil.py": before this patch: ! wall 0.024000 comb 0.015600 user 0.015600 sys 0.000000 (best of 118) after this patch: ! wall 0.023000 comb 0.015600 user 0.015600 sys 0.000000 (best of 123) Status of recent(88d8e568add1) "mercurial/scmutil.py": # of lines: 919 (may affect cost of search) # of bytes: 29633 (may affect cost of "util.binary()") # of matches: 22 (may affect frequency of "util.binary()")
mercurial/commands.py
--- a/mercurial/commands.py	Sat Feb 15 19:52:26 2014 +0900
+++ b/mercurial/commands.py	Sat Feb 15 19:52:36 2014 +0900
@@ -3344,6 +3344,7 @@
         datefunc = ui.quiet and util.shortdate or util.datestr
         found = False
         filerevmatches = {}
+        @util.cachefunc
         def binary():
             flog = getfile(fn)
             return util.binary(flog.read(ctx.filenode(fn)))