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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Feb. 15, 2014, 10:59 a.m.
Message ID <34798e580fada8795f71.1392461975@juju>
Download mbox | patch
Permalink /patch/3669/
State Accepted
Commit a8b4541bb961b53233a2f401adf682be9ed25f3a
Headers show

Comments

Katsunori FUJIWARA - Feb. 15, 2014, 10:59 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1392461556 -32400
#      Sat Feb 15 19:52:36 2014 +0900
# Node ID 34798e580fada8795f71cee5ccb755c4f55e7e7a
# Parent  af90654a3bc55a37e9225eedbfc64008049455b4
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
@@ -3240,6 +3240,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)))