From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#49264: 28.0.50; project.el+tramp performance issue Date: Mon, 9 Aug 2021 03:59:55 +0300 Message-ID: <73afb142-38f4-9e0e-ee46-14ff70db5b72@yandex.ru> References: <20210726165610.7pjiyuz4vtxuhgq7.ref@Ergus> <20210726165610.7pjiyuz4vtxuhgq7@Ergus> <14a3d5a3-33bf-cc82-d144-7302629aa33b@yandex.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------106241B489F0430531B2686B" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13519"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 To: Ergus , 49264@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 09 03:01:16 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCtfI-0003OI-Hs for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 Aug 2021 03:01:16 +0200 Original-Received: from localhost ([::1]:60746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCtfH-0000PF-9f for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 08 Aug 2021 21:01:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCtf4-0000Or-5o for bug-gnu-emacs@gnu.org; Sun, 08 Aug 2021 21:01:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43550) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCtf3-00045t-T8 for bug-gnu-emacs@gnu.org; Sun, 08 Aug 2021 21:01:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mCtf3-00034X-S1 for bug-gnu-emacs@gnu.org; Sun, 08 Aug 2021 21:01:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Aug 2021 01:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49264 X-GNU-PR-Package: emacs Original-Received: via spool by 49264-submit@debbugs.gnu.org id=B49264.162847080611673 (code B ref 49264); Mon, 09 Aug 2021 01:01:01 +0000 Original-Received: (at 49264) by debbugs.gnu.org; 9 Aug 2021 01:00:06 +0000 Original-Received: from localhost ([127.0.0.1]:55096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mCte9-00032C-PP for submit@debbugs.gnu.org; Sun, 08 Aug 2021 21:00:06 -0400 Original-Received: from mail-wr1-f44.google.com ([209.85.221.44]:45620) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mCte7-00031C-D3 for 49264@debbugs.gnu.org; Sun, 08 Aug 2021 21:00:04 -0400 Original-Received: by mail-wr1-f44.google.com with SMTP id m12so19148755wru.12 for <49264@debbugs.gnu.org>; Sun, 08 Aug 2021 18:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=A04rOq0sx1BGJ8OFKMvS4xHMMqd2gb741nf5aFu5VD4=; b=DnLlsP2v4gyBN1nwIfwua0MN06xBlceupnlz+AYJhQTomZogzNraDF7LECo6/1585N HlynR0Hxa6tG51SGuCSPLWPfjtmPE31OELinaR8v68fOxMdroAyHpsAqoTIpgbgDEGYf TmviGfdeQXGWtzO7EyiVq0LYid2QXp/T04nHEG7mgSEDkKDrzr0spqia/DkocErEGeDh qod9DngEfzpl34cTz2kjGsU2o0tQUEeJAYF19HkxYDhGlE2kCeDq77Y/XhSHI4gj4bnc GCW07pqd+Kr5CpgiNmP2YnB66pdwYw4v8KpP9pIHIx37374GFVWFml0Mv/j8ZxlIli2p O0cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:references:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=A04rOq0sx1BGJ8OFKMvS4xHMMqd2gb741nf5aFu5VD4=; b=GE3475w0ZuWPc5ey8613MPeKU1JRAW6dZekweuu3MoLl+NKXjMoNdSp6tZzxyolDDJ lErztDQLiUFNtSMAysa1FLE8lkclxWbIThqxHR6YKMtbar9jcCT7FrasTguXWhMs1zsP Q7lcWMDPNwVm56nKvLiX2PWqUcOE0DgxA/aKKFPlf9Er9wfcKQP2c2S75J9NLCUS0g1Z QFPUat3/gy8+ZW3Z+dlkZ7mWp3OTR/1iZulYhSOovWYl+qMWoKRqYgntAluvBxle91EH 9RHinQ6rRxuarLJE+1Hi0ckVOMaiqkIBKiqI+59bc9miyc/QsD0ua9Urr8ujiyExKrGT vALg== X-Gm-Message-State: AOAM5320Gddm8zG79S7txTkkyAgTqCmRT+pq9v5BQ/3vm/0CMzmYjTm4 DMMBhHgQbkFCPFPatJntq7G16/6IHpw= X-Google-Smtp-Source: ABdhPJxbAczRCkq1FMia6Wi3ofC5Yo7e0odVDqBRTMgBm0+Dd+vDKEpoEG7KMdplKm3CElHmWywyqg== X-Received: by 2002:adf:e48d:: with SMTP id i13mr943753wrm.288.1628470797366; Sun, 08 Aug 2021 17:59:57 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id j19sm21361211wmi.3.2021.08.08.17.59.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Aug 2021 17:59:56 -0700 (PDT) In-Reply-To: <14a3d5a3-33bf-cc82-d144-7302629aa33b@yandex.ru> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:211418 Archived-At: This is a multi-part message in MIME format. --------------106241B489F0430531B2686B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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. --------------106241B489F0430531B2686B Content-Type: text/x-patch; charset=UTF-8; name="project-buffers.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="project-buffers.diff" 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))) + ;;; 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)) --------------106241B489F0430531B2686B--