> perhaps it makes a difference here whether your default-directory is remote 
> or local.
> 
> More general, the pattern (file-remote-p default-directory) is very
> common over Emacs Lisp code. Many packages apply such a check, and
> behave differently depending whether the result is nil or non-nil. 

> Perhaps you have also ideas for benchmarking.

Thanks very much.  See below for the benchmarking I tried.

I evaluated the final progn from *scratch* and then separately (via M-:) from a 
dired buffer in the remote home directory.  In each case I navigated to the 
same remote file on the same host, using exactly the same prefix characters at 
each level (2 of them), followed by TAB.  The remote file was 
`~/node_modules/ext/docs/math/ceil-10.md’, i.e. 4 levels deep.  

Starting from v27.2 emacs -Q, default TAB-based completion UI, here are the 
results I got for the timing of completion-all-completions:

From *scratch*:

        438 calls in 16.970s: 38.7ms/call

From a dired buffer in the remote home directory:

        1045 calls in 3.055s: 2.9ms/call

I’m not certain why this function is called twice as often when your starting 
default-directory is remote, but you can see how much faster it returns.  This 
may not really narrow down the hunt, but at least it shows the effect is real!

For fun I also tried this in my fully-decked out Emacs with vertico UI and 
tramp vs. 2.5.1.2.  Very interestingly, this results in far fewer calls to 
completion-all-completions, but they are also >10x slower when starting from 
*scratch* (similar to the basic case above):

From *scratch*:

        18 calls in 8.110s: 450.6ms/call

From a dired buffer in the remote home directory:

        15 calls in 0.890s: 59.4ms/call

You can guess which one of those feels slow-as-molasses!

> Let me think over night, what we could do for checking (yes, I often
> have my best ideas in bed, when I cannot sleep :-) 

(I hate to wish someone a poor sleep… so: ) Enjoy your weekend, and thanks 
again!

Best,
JDS

+++

(require 'cl-lib)
(require ’tramp)
(defvar my/time)

(defun my/time-advice (func-orig &rest r)
  (let ((time (current-time)) delta)
    (prog1
        (apply func-orig r)
      (setq delta (float-time (time-since time)))
      (cl-incf (car my/time))
      (cl-incf (cadr my/time) delta))))

(setq my/completion-func-to-advise #'completion-all-completions)
(advice-add my/completion-func-to-advise :around #'my/time-advice)
;(advice-remove my/completion-func-to-advise #'my/time-advice)

(progn
  (tramp-cleanup-all-connections)
  (setq my/time '(0 0.0))
  (call-interactively #'find-file)
  (message "%d calls in %0.3fs: %0.1fms/call "
           (car my/time) (cadr my/time) (* 1000 (/ (cadr my/time) (car 
my/time)))))

Reply via email to