emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master 3e4d4f472d: Rework `abbreviate-file-name' in Tramp


From: Jim Porter
Subject: Re: master 3e4d4f472d: Rework `abbreviate-file-name' in Tramp
Date: Mon, 7 Mar 2022 22:22:00 -0800

On 3/7/2022 4:42 AM, Michael Albinus wrote:
branch: master
commit 3e4d4f472d3960a7d18dad76b8d54a66bc5d9f6c
[snip]
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 932dfb3691..5bf6a54020 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
[snip]
@@ -3360,15 +3362,16 @@ Let-bind it when necessary.")
[snip]
              ;; Otherwise, just use the cached value.
-            (tramp-get-connection-property vec "home-directory" nil))))
+            (tramp-get-connection-property vec "~" nil))))
+    (when home-dir
+      (setq home-dir
+           (tramp-compat-funcall
+            'directory-abbrev-apply
+            (tramp-make-tramp-file-name vec home-dir))))
      ;; If any elt of `directory-abbrev-alist' matches this name,
      ;; abbreviate accordingly.

I don't know how much this matters in practice, but one benefit of the old code is that it cached the *abbreviated* home directory (though I gave it a poor name; "home-directory" didn't indicate that it's abbreviated). This can significantly improve performance when there are many entries in `directory-abbrev-alist', since then Tramp doesn't have to abbreviate the home-dir on each call. That's similar to how `abbreviate-file-name' works on local files, which also caches the abbreviated home dir.

See the attached benchmark/results. I also attached a sketch of a patch for a way to avoid that performance cost. I'm not sure it's actually a good way to do things (or even if it's correct in all cases), but hopefully it serves as a demonstration. It would probably be better to cache it somewhere that doesn't persist across sessions though[1]; it could get out of sync with `directory-abbrev-alist' and cause problems (this was a problem with the old code too).

That said, I wouldn't have a problem if the answer is "`directory-abbrev-alist' is short, so caching this value is more trouble than it's worth." The `abbreviate-file-name' function even asks this question (for local files):

      ;; FIXME Is it even worth caching abbreviated-home-dir?
      ;; Ref: https://debbugs.gnu.org/19657#20

- Jim

[1] At least, I *think* Tramp connection properties are cached across Emacs sessions...

Attachment: benchmark.el
Description: Text document

Attachment: results.txt
Description: Text document

Attachment: 0001-Cache-abbreviated-home-directory-for-Tramp.patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]