Subject: bug#41423: 27.0.91; eshell file completion in tramp dir is slow (3 minutes) [regression on pretest]

From: Gregory Heytings <[email-masked]>
Date: Tue, 1 Sep 2020 17:40:41 +0200 (CEST)

>
>> No, the bug is in the completion mechanism, not in eshell.  I don't 
>> know exactly (because the mechanism is so complicated) where the 
>> completion functions should be fixed, but it is clear that there is no 
>> reason to call pcomplete-completions-at-point *three* times.
>
> The reason why it does so, is that it wants to know when a "completion 
> session" terminates, e.g. to hide the *Completions* buffer or to run the 
> exit-function.
>
> So it calls it:
>
> - once to do the actual completion.
> - once per command in post-command-hook to see if we're done.
>
> Since in your example you have 2 commands (TAB and RET), that gives you 
> a total of 3.
>

Hmmm...  It seems to me that in this case, we're done after the first call 
to pcomplete-completions-at-point, so the second call to 
pcomplete-completions-at-point in post-command-hook should see this (or at 
least could see this), and remove completion-in-region--postch from 
post-command-hook.  RET would then not call pcomplete-completions-at-point 
anymore.

>
> This design relies on the fact that completion tables can be lazy, so it 
> should always be possible to make the completion-at-point-function very 
> cheap and harmless, so it's OK to call it repeatedly (or even 
> needlessly).
>

This is not at all documented AFAICS.  Given that it's a crucial aspect 
for your design to work, it should be.

>
>> There is no reason to call pcomplete-completions-at-point when RET is 
>> pressed.
>
> If running that function is costly, it's a bug.
>

It was not before you declared `pcomplete' obsolete and removed 
`eshell-pcomplete'.

>
> That's how completion-at-point-functions was designed.
>
> If you want to change that design, be my guest, but it likely implies 
> changes to a fair bit of code, including outside Emacs.
>

I don't want to change that design, but I ask myself why you documented 
`pcomplete-completions-at-point' as follows:

"Provide standard completion using pcomplete's completion tables. Same as 
`pcomplete' but using the standard completion UI."

It's NOT the same as `pcomplete', it relies on different conditions.  All 
completion functions called by `pcomplete-completions-at-point' should be 
checked and possibly changed with this new design.

Given this, why did you declared `pcomplete' obsolete (it would make sense 
to have both a simple mechanism for simple cases and a more complex one 
for more complex cases), and why did you remove `eshell-pcomplete'?