From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ergus Newsgroups: gmane.emacs.devel Subject: Re: Performance issue in project.el Date: Mon, 28 Jun 2021 13:42:47 +0200 Message-ID: <20210628114247.tecbjwareetquj6h@Ergus> References: <20210627212123.xciejcjxrv2rxsra.ref@Ergus> <20210627212123.xciejcjxrv2rxsra@Ergus> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9018"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jun 28 13:44:27 2021 Return-path: Envelope-to: ged-emacs-devel@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 1lxpgg-0002Ar-Nq for ged-emacs-devel@m.gmane-mx.org; Mon, 28 Jun 2021 13:44:26 +0200 Original-Received: from localhost ([::1]:40508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lxpgf-0006dh-My for ged-emacs-devel@m.gmane-mx.org; Mon, 28 Jun 2021 07:44:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lxpfM-0005hc-HE for emacs-devel@gnu.org; Mon, 28 Jun 2021 07:43:04 -0400 Original-Received: from sonic311-13.consmr.mail.bf2.yahoo.com ([74.6.131.123]:33270) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lxpfK-0006tH-8v for emacs-devel@gnu.org; Mon, 28 Jun 2021 07:43:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1624880581; bh=n/1qhzORpOlceR2Zc6rRXwD65zlo9QmYAlYz2pDSp8Y=; h=Date:From:To:Subject:References:In-Reply-To:From:Subject:Reply-To; b=VoYeGjP3flJuilUQ0FVJHx07Zfa9IuM1dxHVXssx2JNUVf1M0eXVyyz2C5F3Tkpr/ZpTJL3nPfQmUXHkA7wnkK8Q9wvfcy6IkGZwsakUIIvlhZ/HSr5zgGzLly/3Ayk6z3iGfXS2WQSzw1WGeZmmV0MmMRFGOeTNT6cvnVwtHay4mIZ4GspS07oAxuqX9ENLAOBNfUdFH7lHmq5voHi2I7YFJf9dFm+4/SKwEaYzgpu9OtQqZ3jHfCeo2uIvDmUeSHVEbS3oPEY2KPUrfMHpQfv4Ca1qVOuxnRfqX8oDJNKO+uvjTMIzwDfJrksq1IfwhWGg4bj9AqO8S6bdJtIEOA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1624880581; bh=KJLVxktuYjcRO+HW9qN2sgTBhdZXCJTgG6pzc56D1DD=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=ahts3gsgn4iNxpEe9sqN67OslI6JzOtp56fkgUncwA3jnrIrNd/Dl5q7x+PTq0863alT5t6VUf5CoanZhW7yn6JbI+0KMSsnq6dwK5YZBUsXKkyTUP1jiYkmphsFsdfg6xauNmhAU1uSCVHOUpHwTdbvHX7x07NedvQ1FJbMojf7Cvlfgup17pM22H7zvNnV06OGGLF/7vvH+Te2eYli6/sRCsOO7Ie71sxEZmwway0UDTgAd3qaVS8/Da5GbVYpdPHhSwxbVU9FpE88bHxTL6YzBZBY5I5uF0Xph4423brrAaEQbTSSXxXQJnzICAVrJKWtEwUs57IauoPli26myg== X-YMail-OSG: x595KS8VM1lftXeUM.lqyMAgVJT6Vm8odveyIv6IMzPoO6peQC8WbegkF.VqUZU KQnne.LaVbQY5Z8sOpOXynIit63dePeQAftAO32IeylxVpMBuiE_JVHuJDPDWXcFu4B17G.nYhRq X3ZOs_kZ23vmJZkm6Dpf4EaJ0MBJnDFabkI541cJ45xUdUi_MqJRl6eIbC5Pe8MG316zd7WmttiC Uyc9Rgm9R6a.X6HydS39QVwVrVLK9_UbC3CJybO6gB5PJ3_ZHeefYGVzMxdT2YthcMXutiVOp9fu _zZflcTnGlXUkeiTj1rPHhdufnms9sq4U3OkZ5U9QAItJJAr5LQAJoPmSky_b2UurMwEnXL8kgkS jFliV1SDlBVCRdADGu.XNmxsiUNkwlnwLbb77YJ.9ZjQYR_2VOKGkawVF3P2zK8RiDqH2Q_K7OZ3 83kfLiw7oa3Zqt2yEe4Tf7gC9TepaFKa5inGct1FJeBUYD2BScQCasrCEuYZH1eQS1BCt15YwJvI 1_liEDRHnGpqWdRcJsCk2dyHR39lK4wwDpSQSYSexMmSeGE.V0csfoslJIhXn5QjTb7kpfTbWuw6 0yIOfy.lofJn1sMjGgXPDgUIUSqf.0PpCcXw4UVKFA1H_lUcpcSnSkTngxW9X4W5Qa0QdejXPq5i 66vXvy0sgKh8zOMuFbdmPSxZzBHv7tZe8wykU0C_RFLxVeJfT8TK2GXtInxha3kehGCWzJOcVZ4G yBlX9XgoTDrYEmWbU4eh1KNKnjif.rxSGgchCjb6Ru8gHezHxXBtrquMRA73qpaffAbtA7vDCJhW gnXDVj7A6ks9r.gm3LbizGbT._8tzwVzfNSrfuJVeW X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.bf2.yahoo.com with HTTP; Mon, 28 Jun 2021 11:43:01 +0000 Original-Received: by kubenode520.mail-prod1.omega.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID ed0601677ab9b977f40f004636406412; Mon, 28 Jun 2021 11:42:55 +0000 (UTC) Content-Disposition: inline In-Reply-To: <20210627212123.xciejcjxrv2rxsra@Ergus> X-Mailer: WebService/1.1.18469 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol Received-SPF: pass client-ip=74.6.131.123; envelope-from=spacibba@aol.com; helo=sonic311-13.consmr.mail.bf2.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:271062 Archived-At: On Sun, Jun 27, 2021 at 11:21:23PM +0200, Ergus wrote: >Hi: > >Using tramp I tried to use project.el with a command like >project-switch-to-buffer and it took like 10 minutes to complete. > >I ran a profiler and I found that most of the time was taken by: > >project-current called in a loop for all the opened buffers it calls >project--find-in-directory that calls >project-find-functions and there is going all the time. > >I had global-tags-try-project-root (a function from an external package >tat call gnu global program... something like gtags). And I optimized >that function to use a cache and avoid calling the program for every >buffer creating a cache for it. > >Something like: > >``` >(defvar global-tags--dbpath-cache (make-hash-table)) > >(cl-defun global-tags--get-dbpath (&optional (dir default-directory)) > "Filepath for database from DIR." > (pcase (gethash dir global-tags--dbpath-cache) > ('empty nil) > ('nil > (puthash dir 'empty global-tags--dbpath-cache) > (when-let* > === BLA === > (when (file-exists-p dbpath) > (puthash dir dbpath global-tags--dbpath-cache)))) > (code code))) >```` > >Now the time is half than before but still very slow to use the command >(around 3-5 minutes to complete) and running again the profiler I get this: > > 5637 89% - command-execute > 5549 88% - byte-code > 5549 88% - project--read-project-buffer > 5549 88% - let* > 5336 85% - read-buffer > 5323 84% - ivy-completing-read > 5323 84% - ivy-read > 4941 78% - ivy--reset-state > 4941 78% - ivy--buffer-list > 4941 78% - internal-complete-buffer > 4941 78% - # > 4941 78% - and > 4941 78% - equal > 4941 78% - save-current-buffer > 4941 78% - project-current > 4941 78% - project--find-in-directory > 4548 72% - project-try-vc > 4537 72% - vc-responsible-backend > 4478 71% - # > 4478 71% - vc-call-backend > 4478 71% - apply > 1470 23% + vc-svn-responsible-p > 1142 18% + vc-bzr-responsible-p > 970 15% + vc-hg-responsible-p > 390 6% + vc-git-responsible-p > 156 2% + vc-cvs-responsible-p > 126 2% + vc-rcs-responsible-p > 108 1% + vc-sccs-responsible-p > 98 1% + vc-src-responsible-p > 57 0% + tramp-file-name-handler > 11 0% + vc-file-getprop > 393 6% + global-tags-try-project-root > 375 5% + read-from-minibuffer > 13 0% + if > 213 3% + project-current > 88 1% + funcall-interactively > 572 9% + ... > 51 0% + timer-event-handler > 8 0% + redisplay_internal (C function) > > >As you can see most of the time is still taken by project-current and I >can't really understand why: > >1) Are so many samples 4548 seems a very high number for only 25 opened >buffers. > >2) why project-try-vc still takes so much...? Specially for unfrequent >vc systems in our days like svn or bzr that I am not using. > >3) If vc-handled-backends has these value by default: '(RCS CVS SVN SCCS >SRC Bzr Git Hg Mtn) why is there some time taken by vc-hg-responsible-p >that is latter than git in the list? > Just replying to myself about 3) After reading the function vc-responsible-backend I can see that it uses a mapcar to test the responsible; so all of them are always tested in every single call every time. As a workaround I removed all the uninteresting handlers from vc-handled-backends and I get better times now, but IMHO it is still very inefficient almost a minute for project-switch-to-buffer is excessive. VCS changing is not something that happens very often to require a check of all the backends everytime, several times for every buffer in many project.el functions right? Should I open an issue for this? Maybe it is possible to add a sort of optimization like the one mentioned above to vc-responsible-backend? Probably I am wrong, but: Do we really need to check all this everytime we call project-current? I mean, a file or default-dir changes project so often that we need to check with all the backends constantly? Either in the local system the performance penalty seems to be significant. >In any case: > >Maybe (I think I mentioned this before) `project.el` needs a sort of >cache to speedup some functions like `project-current` that are called >very frequently. > >Best, >Ergus >