unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Ergus <spacibba@aol.com>, 49264@debbugs.gnu.org
Subject: bug#49264: 28.0.50; project.el+tramp performance issue
Date: Mon, 9 Aug 2021 03:59:55 +0300	[thread overview]
Message-ID: <73afb142-38f4-9e0e-ee46-14ff70db5b72@yandex.ru> (raw)
In-Reply-To: <14a3d5a3-33bf-cc82-d144-7302629aa33b@yandex.ru>

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

Hi again,

On 27.07.2021 02:04, Dmitry Gutov wrote:
> On 26.07.2021 19:56, Ergus via Bug reports for GNU Emacs, the Swiss army 
> knife of text editors wrote:
>> Any progress/suggestion on this?
> 
> Only internally.
> 
> Let me get back to you on this in a couple of days.

Sorry for the long wait, this feature ties into another old discussion, 
and I wasn't sure how to proceed best.

Anyway, here's a patch to try (attached). It should recover performance 
lost back in 4ca13d98c9e while retaining flexibility (and even adding more).

There are still less than optimal places there (e.g. file-in-directory-p 
is not very fast), and the modules list is read from the disk every 
time, so some further optimization should be possible.

But first please try this version.

[-- Attachment #2: project-buffers.diff --]
[-- Type: text/x-patch, Size: 3124 bytes --]

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 4620ea8f47..f164c19ace 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -51,6 +51,11 @@
 ;; files and its relations to external directories.  `project-files'
 ;; should be consistent with `project-ignores'.
 ;;
+;; `project-buffers' can be overridden if the project has some unusual
+;; shape (e.g. it contains files residing outside of its root, or some
+;; files inside the root must not be considered a part of it). It
+;; should be consistent with `project-files'.
+;;
 ;; This list can change in future versions.
 ;;
 ;; VC project:
@@ -334,6 +339,16 @@ project--remote-file-names
                 (concat remote-id file))
               local-files))))
 
+(cl-defgeneric project-buffers (project)
+  "Return the list of all live buffers that belong to PROJECT."
+  (let ((root (project-root project))
+        bufs)
+    (dolist (buf (buffer-list))
+      (when (file-in-directory-p (buffer-local-value 'default-directory buf)
+                                 root)
+        (push buf bufs)))
+    (nreverse bufs)))
+
 (defgroup project-vc nil
   "Project implementation based on the VC package."
   :version "25.1"
@@ -628,6 +643,23 @@ project--value-in-dir
       (hack-dir-local-variables-non-file-buffer))
     (symbol-value var)))
 
+(cl-defmethod project-buffers ((project (head vc)))
+  (let* ((root (project-root project))
+         (modules (unless (or (project--vc-merge-submodules-p root)
+                              (project--submodule-p root))
+                    (mapcar
+                     (lambda (m) (concat root m))
+                     (project--git-submodules))))
+         dd
+         bufs)
+    (dolist (buf (buffer-list))
+      (setq dd (buffer-local-value 'default-directory buf))
+      (when (and (file-in-directory-p dd root)
+                 (not (cl-find-if (lambda (module) (file-in-directory-p dd module))
+                                  modules)))
+        (push buf bufs)))
+    (nreverse bufs)))
+
 \f
 ;;; Project commands
 
@@ -1014,13 +1046,11 @@ project--read-project-buffer
          (current-buffer (current-buffer))
          (other-buffer (other-buffer current-buffer))
          (other-name (buffer-name other-buffer))
+         (buffers (project-buffers pr))
          (predicate
           (lambda (buffer)
             ;; BUFFER is an entry (BUF-NAME . BUF-OBJ) of Vbuffer_alist.
-            (and (cdr buffer)
-                 (equal pr
-                        (with-current-buffer (cdr buffer)
-                          (project-current)))))))
+            (memq (cdr buffer) buffers))))
     (read-buffer
      "Switch to buffer: "
      (when (funcall predicate (cons other-name other-buffer))
@@ -1160,7 +1190,7 @@ project--buffers-to-kill
 What buffers should or should not be killed is described
 in `project-kill-buffer-conditions'."
   (let (bufs)
-    (dolist (buf (project--buffer-list pr))
+    (dolist (buf (project-buffers pr))
       (when (project--kill-buffer-check buf project-kill-buffer-conditions)
         (push buf bufs)))
     bufs))

  reply	other threads:[~2021-08-09  0:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87fsx13aiz.fsf.ref@aol.com>
2021-06-28 22:11 ` bug#49264: 28.0.50; project.el+tramp performance issue Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-06-29 12:05   ` Eli Zaretskii
2021-06-29 22:21     ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-06-30 12:46       ` Eli Zaretskii
2021-06-30 13:25         ` Phil Sainty
2021-06-30 13:35           ` Eli Zaretskii
2021-06-30 15:10         ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-06-29 13:00   ` Dmitry Gutov
2021-06-30  0:01     ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-07-26 16:56   ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-07-26 23:04     ` Dmitry Gutov
2021-08-09  0:59       ` Dmitry Gutov [this message]
2021-08-17  0:45         ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-19  1:19           ` Dmitry Gutov
2021-08-19  3:08             ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-21  2:23               ` Dmitry Gutov
2021-08-21  5:43                 ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-21 10:59                   ` Dmitry Gutov

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=73afb142-38f4-9e0e-ee46-14ff70db5b72@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=49264@debbugs.gnu.org \
    --cc=spacibba@aol.com \
    /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).