Quite interesting, I can try with an Emacs 28.  But I wonder if you found the 
same discrepancy with Emacs v27.2 I did?  

In the meantime I’ve searched down many rabbit holes and zeroed in on tramp’s 
file handlers.  I am using:

(require 'tramp-sh)
(defun my/test ()
  (interactive)
  (progn
    (tramp-cleanup-all-connections)
    (elp-instrument-list
     '(file-remote-p
       tramp-file-name-handler
       completion-file-name-table
       tramp-handle-substitute-in-file-name
       substitute-in-file-name
       completion--sifn-requote
       file-name-completion
       file-name-all-completions
       completion--file-name-table
       file-exists-p
       completing-read
       read-file-name-internal
       read-file-name-default
       tramp-handle-file-name-completion
       tramp-sh-handle-file-name-all-completions))
    (setq unread-command-events
          (mapcar 'identity "///ssh:datpi:/home/pi/no\tex\t/do\tma\tce\t\n"))
    (call-interactively #'find-file)
    (let ((elp-recycle-buffers-p nil))
      (elp-results)
      (elp-reset-all))))

;; first browse to remote directory (here "pi")
(progn
  (with-current-buffer "pi"
    (my/test))
  (my/test))

For me this implicates file-remote-p and tramp-file-name-handler, which again 
exhibit 10x differences between starting in a local or remote buffer.  If this 
is fixed in Emacs 28 that’s wonderful, but it may be several years before 
everyone has migrated.  

Results:

Starting in *scratch*:

Tramp-file-name-handler                    607         19.486156000  
0.0321023986
read-file-name-default                     1           6.738599      6.738599
completing-read                            1           6.643299      6.643299
substitute-in-file-name                    396         5.9316180000  
0.0149788333
file-remote-p                              1569        5.9054120000  
0.0037638062
tramp-handle-substitute-in-file-name       90          5.8898210000  
0.0654424555
read-file-name-internal                    17          1.420594      
0.0835643529
completion--file-name-table                17          1.420297      
0.0835468823
completion--sifn-requote                   5           1.3667250000  
0.2733450000
completion-file-name-table                 22          0.767013      
0.0348642272
file-name-completion                       6           0.733239      0.1222065
tramp-handle-file-name-completion          6           0.7313359999  
0.1218893333
file-name-all-completions                  6           0.7093809999  
0.1182301666
tramp-sh-handle-file-name-all-completions  6           0.7077049999  
0.1179508333
file-exists-p                              16          0.037264      0.002329

Starting in remote dired buffer “pi”:

tramp-file-name-handler                    1429        3.1352620000  
0.0021940251
read-file-name-default                     1           0.953455      0.953455
completing-read                            1           0.94828       0.94828
completion-file-name-table                 22          0.7587730000  
0.0344896818
file-name-completion                       6           0.7366199999  
0.1227699999
tramp-handle-file-name-completion          6           0.734705      
0.1224508333
file-name-all-completions                  6           0.7178499999  
0.1196416666
tramp-sh-handle-file-name-all-completions  6           0.7160390000  
0.1193398333
substitute-in-file-name                    482         0.3317939999  
0.0006883692
tramp-handle-substitute-in-file-name       167         0.2854299999  
0.0017091616
file-remote-p                              4088        0.1552450000  
3.797...e-05
read-file-name-internal                    17          0.08041       0.00473
completion--file-name-table                17          0.080114      
0.0047125882
file-exists-p                              101         0.0680669999  
0.0006739306
completion--sifn-requote                   5           0.019765      0.003953


> On Sep 19, 2021, at 12:55 PM, Michael Albinus <michael.albi...@gmx.de> wrote:
> 
> JD Smith <jdtsm...@gmail.com> writes:
> 
> Hi,
> 
>> Thanks very much for this much improved testing code (which also saves
>> the tedium of slowly retyping!).  I altered it slightly to include a
>> few more function, and target my local wired server:
>> 
>> (progn
>> (require 'tramp-sh)
>> (tramp-cleanup-all-connections)
>> (elp-instrument-list '(file-exists-p completing-read
>> read-file-name-internal read-file-name-default
>> tramp-handle-file-name-completion
>> tramp-sh-handle-file-name-all-completions))
>> (setq unread-command-events (mapcar 'identity
>> "///ssh:datpi:/home/pi/no\tex\t/do\tma\tce\t\n"))
>> (call-interactively #'find-file)
>> (elp-results)
>> (elp-reset-all))
> 
> I've applied the same, except the remote file name.
> 
> My timing results (emacs -Q, v28.0.50):
> 
> From *scratch*:
> 
> read-file-name-default                     1           9.064781548   
> 9.064781548
> completing-read                            1           9.057834631   
> 9.057834631
> tramp-handle-file-name-completion          3           8.331385864   
> 2.7771286213
> tramp-sh-handle-file-name-all-completions  4           7.290909892   
> 1.822727473
> file-exists-p                              45          1.7296832099  
> 0.0384374046
> read-file-name-internal                    13          0.4099991600  
> 0.0315383969
> 
> From remote dired:
> 
> read-file-name-default                     1           8.23891833    
> 8.23891833
> completing-read                            1           8.228419034   
> 8.228419034
> tramp-handle-file-name-completion          3           7.4998795480  
> 2.4999598493
> tramp-sh-handle-file-name-all-completions  4           6.463144493   
> 1.6157861232
> file-exists-p                              45          1.6901479139  
> 0.0375588425
> read-file-name-internal                    13          0.3952138859  
> 0.0304010681
> 
>> So really only very little difference inside the tramp completion
>> functions; they seem to be doing the same job independent of the
>> starting point.  But the completing-read itself, which is where
>> find-file is spending its time, is taking 8x longer!  And
>> read-file-name-internal is 35x slower.  Do you find this as well? 
>> I’ll dig a bit deeper and see if I can narrow it down further. 
> 
> With Emacs 28, the differences aren't so relevant. The absolute time is
> much higher than in your case, but I have taken "savannah" as test host
> which is "far from me".
> 
> Do you have a chance to compile Emacs from git, and run the test?
> 
> Best regards, Michael.

Reply via email to