From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.bugs Subject: bug#70036: a fix that Date: Tue, 30 Apr 2024 11:30:39 +0000 Message-ID: <87r0enozog.fsf@localhost> References: <4e670617-6483-4159-a5cf-27a921764c38@email.android.com> <864jbxden1.fsf@gnu.org> <877cgt7ptk.fsf@localhost> <86sezhbp7g.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33020"; mail-complaints-to="usenet@ciao.gmane.io" Cc: theo@thornhill.no, 70036@debbugs.gnu.org, felician.nemeth@gmail.com, joaotavora@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 30 13:31:02 2024 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 1s1lhN-0008Ih-H2 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 30 Apr 2024 13:31:01 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1lhC-00054Q-3w; Tue, 30 Apr 2024 07:30:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1lh4-00050R-3n for bug-gnu-emacs@gnu.org; Tue, 30 Apr 2024 07:30:47 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1lh3-00085G-DE for bug-gnu-emacs@gnu.org; Tue, 30 Apr 2024 07:30:41 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s1lhN-0007QR-UJ for bug-gnu-emacs@gnu.org; Tue, 30 Apr 2024 07:31:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ihor Radchenko Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 30 Apr 2024 11:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70036 X-GNU-PR-Package: emacs Original-Received: via spool by 70036-submit@debbugs.gnu.org id=B70036.171447661922559 (code B ref 70036); Tue, 30 Apr 2024 11:31:01 +0000 Original-Received: (at 70036) by debbugs.gnu.org; 30 Apr 2024 11:30:19 +0000 Original-Received: from localhost ([127.0.0.1]:59395 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s1lgW-0005FU-F3 for submit@debbugs.gnu.org; Tue, 30 Apr 2024 07:30:19 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:40471) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s1lgT-0004sV-1b for 70036@debbugs.gnu.org; Tue, 30 Apr 2024 07:30:06 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 89657240105 for <70036@debbugs.gnu.org>; Tue, 30 Apr 2024 13:29:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1714476578; bh=G+WS+ELan3bp0iTqUR0ePThlmgfihv2wR5SpC+MfSNk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=as3SmemyELBcb5kwTuYMb3xjHo11TbsFIbfWuwZgUcD7R1CUCcRnzbSx89A00r+KU W2dOkhWGidk2tQLxkIgYzyLhfzi7WI3CF7fNd5YwEkZ48ggaO07AtAvXPjzjpdbem/ Ttd8jkxbaTKG1tYRo/Wjr6ihaoV2YzJ58seHQXYWi7f0pweu9fk2YfaS2Qq9E6BROR 2XgdrB62cSiaoOsEEhNMIOCvcAa6OURH7qIAg+Mlqf7Y5UEDOn1HFPWI9QKZJ1yKDA BovmYkUdfSmd47FiOGAiIZJikGDCxjjPBHPk6dnFAW1LV3l/PVrzxk2a13ySanHnQ9 aUIYwrNqJDtNg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VTHzP2Ckvz9rxB; Tue, 30 Apr 2024 13:29:36 +0200 (CEST) In-Reply-To: <86sezhbp7g.fsf@gnu.org> 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:284200 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> There are some easy things that can be done to improve `file-truename' >> performance somewhat. For example, the number of calls to >> `file-name-nondirectory' can be trivially reduced in the `file-truename' >> code - it is called up to three times in a row. >> >> (see my earlier message in https://yhetil.org/emacs-bugs/87jzlmd831.fsf@localhost/) >> >> Will it be of interest? > > Yes, of course. Those kinds of changes are no-brainers, really. See the attached patch. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Improve-performance-of-file-truename-bug-70036.patch >From cde58b309588008707cc8b00919eb24801e42eb6 Mon Sep 17 00:00:00 2001 Message-ID: From: Ihor Radchenko Date: Tue, 30 Apr 2024 14:27:04 +0300 Subject: [PATCH] Improve performance of `file-truename' (bug#70036) * lisp/files.el (file-truename): Avoid repetitive calls to `file-name-nondirectory'. These calls contribute significantly to CPU time. See the benchmarks in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=70036#47 --- lisp/files.el | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index 7dec67c5cf0..b7ebb727c72 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1504,27 +1504,28 @@ file-truename (new (file-name-as-directory (file-truename dirfile counter prev-dirs)))) (setcar prev-dirs (cons (cons old new) (car prev-dirs))) (setq dir new)))) - (if (equal ".." (file-name-nondirectory filename)) - (setq filename - (directory-file-name (file-name-directory (directory-file-name dir))) - done t) - (if (equal "." (file-name-nondirectory filename)) - (setq filename (directory-file-name dir) - done t) - ;; Put it back on the file name. - (setq filename (concat dir (file-name-nondirectory filename))) - ;; Is the file name the name of a link? - (setq target (file-symlink-p filename)) - (if target - ;; Yes => chase that link, then start all over - ;; since the link may point to a directory name that uses links. - ;; We can't safely use expand-file-name here - ;; since target might look like foo/../bar where foo - ;; is itself a link. Instead, we handle . and .. above. - (setq filename (files--splice-dirname-file dir target) - done nil) - ;; No, we are done! - (setq done t)))))))) + (let ((filename-no-dir (file-name-nondirectory filename))) + (if (equal ".." filename-no-dir) + (setq filename + (directory-file-name (file-name-directory (directory-file-name dir))) + done t) + (if (equal "." filename-no-dir) + (setq filename (directory-file-name dir) + done t) + ;; Put it back on the file name. + (setq filename (concat dir filename-no-dir)) + ;; Is the file name the name of a link? + (setq target (file-symlink-p filename)) + (if target + ;; Yes => chase that link, then start all over + ;; since the link may point to a directory name that uses links. + ;; We can't safely use expand-file-name here + ;; since target might look like foo/../bar where foo + ;; is itself a link. Instead, we handle . and .. above. + (setq filename (files--splice-dirname-file dir target) + done nil) + ;; No, we are done! + (setq done t))))))))) filename)) (defun file-chase-links (filename &optional limit) -- 2.44.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--