|
From: | JD Smith |
Subject: | Re: File path completions: strange speed discrepancy |
Date: | Mon, 20 Sep 2021 17:46:32 -0400 |
which occurs with both remote and local start (even more times for the remote start). I found DARWIN_USER_TEMP_DIR mentioned in cus-start.el, and it is obviously mac specific. There is the interesting related docstring:
So a canonical local vs remote difference, as you mentioned. To investigate further, first I explicitly set my shell-file-name to “/bin/bash”. This radically improves things: local and remote are much closer to the same speed now. But still, the issue remains, why is DARWIN_USER_TEMP_DIR being queried via shell-command-to-string so often? This variable is just a startup constant, taken ONCE from the environment, or from getconf (as a backup in case getenv fails). The traceback is revealing: shell-command-to-string("getconf DARWIN_USER_TEMP_DIR") (progn (shell-command-to-string "getconf DARWIN_USER_TEMP_DIR")) (condition-case nil (progn (shell-command-to-string "getconf DARWIN_USER_TEMP_DIR")) (error nil)) (ignore-errors (shell-command-to-string "getconf DARWIN_USER_TEMP_DIR")) (let* (file-name-handler-alist (tmp (ignore-errors (shell-command-to-string "getconf DARWIN_USER_TEMP_DIR")))) (and (stringp tmp) (setq tmp (replace-regexp-in-string "\n\\'" "" tmp)) (file-directory-p tmp) tmp)) (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") (let* (file-name-handler-alist (tmp (ignore-errors (shell-command-to-string "getconf DARWIN_USER_TEMP_DIR")))) (and (stringp tmp) (setq tmp (replace-regexp-in-string "\n\\'" "" tmp)) (file-directory-p tmp) tmp)) "/tmp") (cond ((memq system-type '(ms-dos windows-nt)) (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp")) ((eq system-type 'darwin) (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") (let* (file-name-handler-alist (tmp (ignore-errors (shell-command-to-string "getconf DARWIN_USER_TEMP_DIR")))) (and (stringp tmp) (setq tmp (replace-regexp-in-string "\n\\'" "" tmp)) (file-directory-p tmp) tmp)) "/tmp")) (t (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))) (file-name-as-directory (cond ((memq system-type '(ms-dos windows-nt)) (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp")) ((eq system-type 'darwin) (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") (let* (file-name-handler-alist (tmp (ignore-errors ...))) (and (stringp tmp) (setq tmp (replace-regexp-in-string "\n\\'" "" tmp)) (file-directory-p tmp) tmp)) "/tmp")) (t (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp")))) eval((file-name-as-directory (cond ((memq system-type '(ms-dos windows-nt)) (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp")) ((eq system-type 'darwin) (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") (let* (file-name-handler-alist (tmp ...)) (and (stringp tmp) (setq tmp ...) (file-directory-p tmp) tmp)) "/tmp")) (t (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))) tramp-sh-handle-expand-file-name("/ssh:tir:/home/jdsmith/code/python/scraps/Untitled..." nil) apply(tramp-sh-handle-expand-file-name ("/ssh:tir:/home/jdsmith/code/python/scraps/Untitled..." nil)) tramp-sh-file-name-handler(expand-file-name "/ssh:tir:/home/jdsmith/code/python/scraps/Untitled..." nil) apply(tramp-sh-file-name-handler expand-file-name ("/ssh:tir:/home/jdsmith/code/python/scraps/Untitled..." nil)) tramp-file-name-handler(expand-file-name "/ssh:tir:/home/jdsmith/code/python/scraps/Untitled..." nil) Stepping through `tramp-sh-handle-expand-file-name', I noticed that, after the main SSH connection is established, every other invocation of `tramp-compat-temporary-file-directory’ spawns a new shell with getconf DARWIN_USER_TEMP_DIR. And, at long last, HERE we see the problem, in `tramp-compat-temporary-file-directory':
Why is this an issue? That standard value of `temporary-file-directory' contains, for 'darwin systems:
So, to recap my understanding of this issue:
One thing I don’t understand is why tramp needs to re-evaluate the standard value of the variable `temporary-file-directory’ at all. That variable doesn’t appear to change on remote hosts, or ever really. What does change is the returned result of the identically-name function `temporary-file-directory’. A quick fix for me was simply to (see FIXED timing, below):
With this, my tramp file browsing is blazingly fast, whether starting local or remote, with Emacs 27.2 and tramp 2.4.3-pre. Some timing, from my earlier test:
I note that this remains an issue in Emacs 28.1 and Tramp v2.5.1.2. I would not be at all surprised if this also underlies many of the complaints about tramp performance on MacOS (e.g. https://emacs.stackexchange.com/questions/16489/tramp-is-unbearably-slow-osx-ssh), for people who have slow-to-start shells. Thanks for your help with this (and as always, for Tramp, which is unique and incredibly useful). Best, JDS
|
[Prev in Thread] | Current Thread | [Next in Thread] |