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: Thu, 19 Aug 2021 04:19:20 +0300 Message-ID: References: <20210726165610.7pjiyuz4vtxuhgq7.ref@Ergus> <20210726165610.7pjiyuz4vtxuhgq7@Ergus> <14a3d5a3-33bf-cc82-d144-7302629aa33b@yandex.ru> <73afb142-38f4-9e0e-ee46-14ff70db5b72@yandex.ru> <20210817004551.25qheo6v2gfys3ie@Ergus> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------C682CBA70B2A03444050029C" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9125"; 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 Cc: 49264@debbugs.gnu.org To: Ergus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 19 03:20:21 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 1mGWjF-0002ER-2D for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 19 Aug 2021 03:20:21 +0200 Original-Received: from localhost ([::1]:53788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mGWjC-000139-FS for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Aug 2021 21:20:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGWix-00010x-Iz for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2021 21:20:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46252) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mGWiw-00065Q-ER for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2021 21:20:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mGWiw-0006hx-5r for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2021 21:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Aug 2021 01:20:02 +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.162933597325739 (code B ref 49264); Thu, 19 Aug 2021 01:20:02 +0000 Original-Received: (at 49264) by debbugs.gnu.org; 19 Aug 2021 01:19:33 +0000 Original-Received: from localhost ([127.0.0.1]:57798 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mGWiT-0006h4-Db for submit@debbugs.gnu.org; Wed, 18 Aug 2021 21:19:33 -0400 Original-Received: from mail-wr1-f44.google.com ([209.85.221.44]:33642) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mGWiP-0006go-7U for 49264@debbugs.gnu.org; Wed, 18 Aug 2021 21:19:33 -0400 Original-Received: by mail-wr1-f44.google.com with SMTP id r7so6405800wrs.0 for <49264@debbugs.gnu.org>; Wed, 18 Aug 2021 18:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=sXRUEwQcPhVBBIRNBdGs3lHSTG0MeKma/LYTyMTAXpI=; b=fMSTN2h0/aKcO7GJ3SE6fnH8Dqm/fFeSkgd3/ZqTdTmVIHi0tum51l4hP5546/tsdR BzQtjgen/VdYmFvJKqWVhsTK7rfqmjiu6QYgFqH8bkWO30+DG1TNzHyC2a2HU4K1XwBZ MCPRqGR0M5tBF9ob7FVyOLFotgbh3mFtd9W6odakfxobeDWOBbMCEhAgYYfK1nPz5s83 SH3y47Yxo5Hk9Fhcozl6OQOTs63gQQc5dsHtfBLWsrDyrdw9ipob8BN5HRyil+FyEQl1 PENkxc1Wc4ic8rdGGKhSPZ55oqhf4DeaAVrvmT7YiYcpqUTONi5I5JJONdd1DflRmtOl vrHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=sXRUEwQcPhVBBIRNBdGs3lHSTG0MeKma/LYTyMTAXpI=; b=j7XclmOdos6+59+iln+OY8sB/F4vLkt2N5KJhKeoJueV0osDWRBxHzDIzOoNnd3kkq a/VqriCDXXIsFybuU7+IDm07SRxLIrtLiVMJzkRE839fhVvKIsTafXO7UYTPRPh/+fPK Lz11WkOEFdTfmu/XaCg+sCkutOpYY0ok92U+s1hPcE8slmFH40GvkbIok+fq5tRau2c1 an4wJVmmFHoyKhwNQwTAFMNkNZPu4Sv7Exky6bQIxGsUzF+NM1aZrEzBL5RGt8WGdYIB itTJ+G9DCjrgQWtNbo2/O5AdIdr8ARbGIz1pVx4KD/gHYXssVUdf32dpOnvjXBnsZk62 OTFQ== X-Gm-Message-State: AOAM530FbotGW/JDlRQJt6SbjQjEA84Pq1+Nb88hjYHeaU2BoB14SCTz 5MrQ3p4oVe24OlFtkz/T8T+n97vXzfk= X-Google-Smtp-Source: ABdhPJx1fuaIuz7cvt5UOyS4KywKATyeYangnTEMUV37WH5vjVN23Y0evqfEU6DbKjxIOsGZIHK8/g== X-Received: by 2002:a5d:6301:: with SMTP id i1mr380377wru.423.1629335963211; Wed, 18 Aug 2021 18:19:23 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id s141sm1123822wme.6.2021.08.18.18.19.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 18:19:22 -0700 (PDT) In-Reply-To: <20210817004551.25qheo6v2gfys3ie@Ergus> 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:212190 Archived-At: This is a multi-part message in MIME format. --------------C682CBA70B2A03444050029C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Ergus, On 17.08.2021 03:45, Ergus wrote: > I made a manual fast profiling and I see that most of the time in > project-buffers actually goes to tramp-sh-file-name-handler. > >          207  42%         - project-buffers >          207  42%          - apply >          207  42%           - # >          200  40%            - file-in-directory-p >          200  40%             - tramp-file-name-handler >          197  40%              - apply >          197  40%               - tramp-sh-file-name-handler >          197  40%                - tramp-handle-file-in-directory-p >          183  37%                 - tramp-run-real-handler >          183  37%                  - file-in-directory-p >          124  25%                   - file-equal-p >          124  25%                    - tramp-file-name-handler >          121  24%                     - apply >          121  24%                      - tramp-sh-file-name-handler >          121  24%                       - tramp-handle-file-equal-p >           85  17%                        - tramp-run-real-handler >           85  17%                         - file-equal-p >           52  10%                          - file-truename >           52  10%                           - tramp-file-name-handler >           41   8%                            - apply >           41   8%                             - tramp-sh-file-name-handler >           41   8%                              - > tramp-sh-handle-file-truename >           28   5%                               + file-remote-p >           10   2%                               + file-local-name >            3   0%                               + file-name-as-directory > > It goes specifically to file-in-directory-p as you said. So maybe the > improvement there may be also desirable if the difference after the > optimization can reduce the time for file-in-directory-p (or the caller) > at least to the half. Thanks for testing. Try the attached new version please. It should eliminate that particular bottleneck. --------------C682CBA70B2A03444050029C 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..f9b302bb2b 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 (expand-file-name (file-name-as-directory (project-root project)))) + bufs) + (dolist (buf (buffer-list)) + (when (string-prefix-p root (expand-file-name + (buffer-local-value 'default-directory buf))) + (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 (expand-file-name (file-name-as-directory (project-root project)))) + (modules (unless (or (project--vc-merge-submodules-p root) + (project--submodule-p root)) + (mapcar + (lambda (m) (format "%s%s/" root m)) + (project--git-submodules)))) + dd + bufs) + (dolist (buf (buffer-list)) + (setq dd (expand-file-name (buffer-local-value 'default-directory buf))) + (when (and (string-prefix-p root dd) + (not (cl-find-if (lambda (module) (string-prefix-p module dd)) + 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)) --------------C682CBA70B2A03444050029C--