unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Eli Zaretskii <eliz@gnu.org>,
	emacs-devel@gnu.org, andreyk.mad@gmail.com,
	 monnier@iro.umontreal.ca
Subject: Re: Change in vc-git ls-files-unknown makes emacs hang
Date: Fri, 20 Dec 2019 16:13:59 +0200	[thread overview]
Message-ID: <3df8e670-91f7-0f56-927d-8c2063b33fe1@yandex.ru> (raw)
In-Reply-To: <m2tv5v8e0n.fsf@fastmail.fm>

[-- Attachment #1: Type: text/plain, Size: 804 bytes --]

On 20.12.2019 12:52, Filipp Gunbin wrote:

>> Filipp, please produce a backtrace during the freeze, either by using
>> SIGUSR2, as Stefan suggested, or by attaching a debugger, and post the
>> backtrace.
> 
> Hi, please find the trace in the attach (it's large).

Thank you. It doesn't exactly answer my question about desktop-read (did 
you really have an old VC-Dir buffer in that saved session?), but it 
shows one bottleneck. One that is even prominently decorated with an old 
comment saying "this is VERY inefficient". :-)

Here's a patch you can try. It should help to an extent. And if it's the 
main bottleneck, we can optimize further, e.g. by eliminating the 
expand-file-name calls.

But if in the end you should see one very long VC-Dir buffer, which can 
be a usability problem on its own.

[-- Attachment #2: vc-dir-update-faster.diff --]
[-- Type: text/x-patch, Size: 1708 bytes --]

diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index e225978592..ad25e8aa53 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -390,19 +390,22 @@ vc-dir-update
     ;; We assume the ewoc is sorted too, which should be the
     ;; case if we always add entries with vc-dir-update.
     (setq entries
+          (let ((entry-dirs
+                 (mapcar (lambda (entry)
+                           (cons (file-name-directory
+                                  (directory-file-name (expand-file-name (car entry))))
+                                 entry))
+                         entries)))
 	  ;; Sort: first files and then subdirectories.
-	  ;; XXX: this is VERY inefficient, it computes the directory
-	  ;; names too many times
-	  (sort entries
-		(lambda (entry1 entry2)
-		  (let ((dir1 (file-name-directory
-			        (directory-file-name (expand-file-name (car entry1)))))
-			(dir2 (file-name-directory
-			       (directory-file-name (expand-file-name (car entry2))))))
-		    (cond
-		     ((string< dir1 dir2) t)
-		     ((not (string= dir1 dir2)) nil)
-		     ((string< (car entry1) (car entry2))))))))
+            (mapcar #'cdr
+                    (sort entry-dirs
+                          (lambda (pair1 pair2)
+                            (let ((dir1 (car pair1))
+                                  (dir2 (car pair2)))
+                              (cond
+                               ((string< dir1 dir2) t)
+                               ((not (string= dir1 dir2)) nil)
+                               ((string< (cadr pair1) (cadr pair2))))))))))
     ;; Insert directory entries in the right places.
     (let ((entry (car entries))
 	  (node (ewoc-nth vc-ewoc 0))

  reply	other threads:[~2019-12-20 14:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19 14:16 Change in vc-git ls-files-unknown makes emacs hang Filipp Gunbin
2019-12-19 14:41 ` Dmitry Gutov
2019-12-19 20:44   ` Filipp Gunbin
2019-12-19 22:42     ` Dmitry Gutov
2019-12-20  7:33       ` Eli Zaretskii
2019-12-20 10:52         ` Filipp Gunbin
2019-12-20 14:13           ` Dmitry Gutov [this message]
2019-12-20 15:36             ` Filipp Gunbin
2019-12-20 15:40               ` Dmitry Gutov
2019-12-20 17:14                 ` Filipp Gunbin
2019-12-20 22:18                   ` Dmitry Gutov
2019-12-21 21:51         ` Proced signals (was: Change in vc-git ls-files-unknown makes emacs hang) Juri Linkov
2019-12-22 17:02           ` Eli Zaretskii
2019-12-19 20:45 ` Change in vc-git ls-files-unknown makes emacs hang Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3df8e670-91f7-0f56-927d-8c2063b33fe1@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=andreyk.mad@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).