From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#11757: Acknowledgement (24.1.50; vc-git calls `process-file' too many times) Date: Thu, 28 Jun 2012 04:51:54 +0400 Message-ID: <4FEBAAAA.3030102@yandex.ru> References: <4FE2832A.1030308@yandex.ru> <4FE994E8.9020605@yandex.ru> <87zk7qs21q.fsf@gmx.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010603000800080203080903" X-Trace: dough.gmane.org 1340844782 8476 80.91.229.3 (28 Jun 2012 00:53:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 28 Jun 2012 00:53:02 +0000 (UTC) Cc: 11757@debbugs.gnu.org To: Michael Albinus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 28 02:53:01 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sk2yi-00012z-Dn for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Jun 2012 02:53:00 +0200 Original-Received: from localhost ([::1]:37279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sk2yi-0003VC-AL for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Jun 2012 20:53:00 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:60873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sk2ye-0003V6-HT for bug-gnu-emacs@gnu.org; Wed, 27 Jun 2012 20:52:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sk2yb-0007ma-EQ for bug-gnu-emacs@gnu.org; Wed, 27 Jun 2012 20:52:56 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51845) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sk2yb-0007mR-3y for bug-gnu-emacs@gnu.org; Wed, 27 Jun 2012 20:52:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Sk32b-0008BL-Lm for bug-gnu-emacs@gnu.org; Wed, 27 Jun 2012 20:57:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Jun 2012 00:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11757 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 11757-submit@debbugs.gnu.org id=B11757.134084496731383 (code B ref 11757); Thu, 28 Jun 2012 00:57:01 +0000 Original-Received: (at 11757) by debbugs.gnu.org; 28 Jun 2012 00:56:07 +0000 Original-Received: from localhost ([127.0.0.1]:33158 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Sk31i-0008A7-FE for submit@debbugs.gnu.org; Wed, 27 Jun 2012 20:56:07 -0400 Original-Received: from forward4.mail.yandex.net ([77.88.46.9]:33908) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Sk31d-00089g-JC for 11757@debbugs.gnu.org; Wed, 27 Jun 2012 20:56:04 -0400 Original-Received: from smtp2.mail.yandex.net (smtp2.mail.yandex.net [77.88.46.102]) by forward4.mail.yandex.net (Yandex) with ESMTP id DF6031BC1DC3; Thu, 28 Jun 2012 04:51:50 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1340844710; bh=SpbpU8FXIjOUsutup8ozRXsHo/zL1FQ5Orl7MnxTyeA=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type; b=MfOKJRSH1Mz6YjOLptmxte7z5q98dJ2cSzgpfFC58HpjFB1dKXUnIFBEBPGkAXIRL xEc54EX83rKggfOsPEpq7oHsbdj9V6BmctLv4b9wqfsE3UIEYuBdWDzbdHHPvSah6+ 3ZsiIMbIB1RJCRtnRA4zzP5N/0q6g55i7bCWwLPA= Original-Received: from smtp2.mail.yandex.net (localhost [127.0.0.1]) by smtp2.mail.yandex.net (Yandex) with ESMTP id BE9FCE20555; Thu, 28 Jun 2012 04:51:50 +0400 (MSK) Original-Received: from 98-87.nwlink.spb.ru (98-87.nwlink.spb.ru [178.252.98.87]) by smtp2.mail.yandex.net (nwsmtp/Yandex) with ESMTP id poYSOa4p-poYGkP4G; Thu, 28 Jun 2012 04:51:50 +0400 X-Yandex-Rcpt-Suid: michael.albinus@gmx.de X-Yandex-Rcpt-Suid: 11757@debbugs.gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1340844710; bh=SpbpU8FXIjOUsutup8ozRXsHo/zL1FQ5Orl7MnxTyeA=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type; b=RwMC7IvLa4nh3HnX6okRjyZo5xME8V6DuX1tX6Nv3X7zv/+OukCvS4bEyK8AcLq/c bNSIxZQH6LZHCCiffmpS7zWP0WWUED9joUw76GS22/Xfol3Enfpbsn1OKYyU1NrXp1 xp/NlL3/ka8wkSfIaWZZPhuGb4k0PzXbq0MSsido= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: <87zk7qs21q.fsf@gmx.de> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:61349 Archived-At: This is a multi-part message in MIME format. --------------010603000800080203080903 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi Michael, This little patch shaves 2 `process-file' invocations from both `vc-find-file-hook' and `vc-after-save'. It's not fully backward-compatible (it breaks when a previously registered file became unregistered), but I think it's a good tradeoff. VC doesn't handle all cases of "outside interference" anyway: for example, the cached return value of `vc-working-revision' is invalidated only after the file is checked in, moved, or deleted, not after each save, and switching to another branch in Git is a much more common occurrence. A more complex solution, though also applicable to vc-hg, would be to move most of the code from `vc-git-registered' to `vc-git-state', then modify `vc-git-registered' and `vc-hg-registered' to call `vc-state' (for caching) and then interpret its return value (what `vc-hg-registered' already does). Since `vc-registered' calls `vc-xx-registered' functions when selecting the backend, we'd also need to clear the cached 'vc-state value after each call with negative result. This would mean +1 `process-file' invocation with Git in `vc-after-save', compared to the attached patch, but -1 with Hg in `vc-find-file-hook'. On 26.06.2012 16:14, Michael Albinus wrote: > Dmitry Gutov writes: > >> After setting vc-git-program explicitly to "C:/Program Files >> (x86)/Git/bin/git.exe" (by default, it was calling "C:/Program Files >> (x86)/Git/cmd/git.CMD"), the average time of git command calls went >> down from 0.2s to 0.03s, so the problem with Git is about 7 times less >> important now. > > If the git repository is remote (accessed via Tramp), this is still a > serious issue. I'm plagued by this every single day. Less `process-file' > invocations would be more than welcome. Maybe vc-git can cache some results? > >> -- Dmitry > > Best regards, Michael. > > --------------010603000800080203080903 Content-Type: text/plain; charset=windows-1251; name="0004-vc-git.el-vc-git-state-Don-t-call-vc-git-registered-.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0004-vc-git.el-vc-git-state-Don-t-call-vc-git-registered-.pa"; filename*1="tch" >From 8035692de90e463aa83576d68c6d008f77362fdc Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Thu, 28 Jun 2012 04:01:06 +0400 Subject: [PATCH 4/4] * vc-git.el (vc-git-state): Don't call `vc-git-registered', it's expensive. It's possible that file's status had changed to 'unregistered' since it was opened, but is checking this worth another process call? Note that if this is the case, `vc-next-action' won't add the file now. (vc-git-mode-line-string): Call `vc-working-revision' instead of `vc-git-working-revision' because it caches the result. --- lisp/vc/vc-git.el | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 63243cd..329a950 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -215,23 +215,25 @@ matching the resulting Git log output, and KEYWORDS is a list of ;; is direct ancestor of corresponding upstream branch, and the file ;; was modified upstream. But we can't check that without a network ;; operation. - (if (not (vc-git-registered file)) - 'unregistered - (let ((diff (vc-git--run-command-string - file "diff-index" "-p" "--raw" "-z" "HEAD" "--"))) - (if (and diff - (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\([ADMUT]\\)\0[^\0]+\0\\(.*\n.\\)?" - diff)) - (let ((diff-letter (match-string 1 diff))) - (if (not (match-beginning 2)) - ;; Empty diff: file contents is the same as the HEAD - ;; revision, but timestamps are different (eg, file - ;; was "touch"ed). Update timestamp in index: - (prog1 'up-to-date - (vc-git--call nil "add" "--refresh" "--" - (file-relative-name file))) - (vc-git--state-code diff-letter))) - (if (vc-git--empty-db-p) 'added 'up-to-date))))) + ;; This assumes that status is known to be not `unregistered' because + ;; we've been successfully dispatched here from `vc-state', that + ;; means `vc-git-registered' returned t earlier once. Not 100% accurate, + ;; but close enough. + (let ((diff (vc-git--run-command-string + file "diff-index" "-p" "--raw" "-z" "HEAD" "--"))) + (if (and diff + (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\([ADMUT]\\)\0[^\0]+\0\\(.*\n.\\)?" + diff)) + (let ((diff-letter (match-string 1 diff))) + (if (not (match-beginning 2)) + ;; Empty diff: file contents is the same as the HEAD + ;; revision, but timestamps are different (eg, file + ;; was "touch"ed). Update timestamp in index: + (prog1 'up-to-date + (vc-git--call nil "add" "--refresh" "--" + (file-relative-name file))) + (vc-git--state-code diff-letter))) + (if (vc-git--empty-db-p) 'added 'up-to-date)))) (defun vc-git-working-revision (_file) "Git-specific version of `vc-working-revision'." @@ -248,7 +250,7 @@ matching the resulting Git log output, and KEYWORDS is a list of (defun vc-git-mode-line-string (file) "Return a string for `vc-mode-line' to put in the mode line for FILE." - (let* ((branch (vc-git-working-revision file)) + (let* ((branch (vc-working-revision file 'Git)) (def-ml (vc-default-mode-line-string 'Git file)) (help-echo (get-text-property 0 'help-echo def-ml))) (if (zerop (length branch)) -- 1.7.10.msysgit.1 --------------010603000800080203080903--