Patchwork [3,of,5] grep: reuse the first "util.binary()" result for efficiency

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Jan. 18, 2014, 3:24 p.m.
Message ID <2f2ef51e1f5ef435fee4.1390058640@vm-debian.dzone.foozy.private>
Download mbox | patch
Permalink /patch/3382/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - Jan. 18, 2014, 3:24 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1390058567 -32400
#      Sun Jan 19 00:22:47 2014 +0900
# Node ID 2f2ef51e1f5ef435fee4f618bd2db791531b6627
# Parent  3a11772a30d072c0de2535feac4d9b04e0866041
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()")

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3231,6 +3231,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)))