unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Daniel Mendler <mail@daniel-mendler.de>
To: Juri Linkov <juri@linkov.net>
Cc: Gregory Heytings <gregory@heytings.org>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	Dmitry Gutov <dgutov@yandex.ru>
Subject: Re: [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH)
Date: Sun, 25 Apr 2021 23:26:11 +0200	[thread overview]
Message-ID: <4d9971af-9af1-97a6-61fc-d88d4d192dcc@daniel-mendler.de> (raw)
In-Reply-To: <87k0oqf5z7.fsf@mail.linkov.net>

On 4/25/21 10:45 PM, Juri Linkov wrote:> I tried and it looks really 
nice.  One question about performance:
 > there are 3 calls of the same function on every completion candidate:
 > twice it's called with the nil arg, and one call with the 'transform' 
arg:

Thanks, I am glad you like the UI.

 >> +(defun minibuffer--group-by (fun elems)
 >> +      (let* ((key (funcall fun cand nil))
 >
 >> @@ -1780,6 +1829,12 @@ completion--insert-strings
 >> +          (let ((title (funcall group-fun (if (consp str) (car str) 
str) nil)))
 >
 >> @@ -1825,8 +1880,15 @@ completion--insert-strings
 >> +                        (funcall group-fun str 'transform)
 >
 >> @@ -2098,15 +2171,22 @@ minibuffer-completion-help
 >> +                              (minibuffer--group-by group-fun 
completions)))
 >
 > My concern is how fast it will work on a large list of candidate strings?

The current implementation already focuses quite a bit on efficiency 
since I am using it in my continuously updating vertical UI (Vertico). 
The function `minibuffer--group-by` is linear time and significantly 
faster than the sorting which comes before it. It is crucial that the 
group function does not allocate when called with transform=nil, 
otherwise `minibuffer--group-by` would lead to a slowdown.

Then the calls to the group function with transform/=nil are allowed to 
be more costly, since they only occur for the candidates which are 
displayed by the UI. These calls will then not matter in comparison to 
the other costs of displaying the candidates.

 > Would it be possible to optimize it to call the group function only once
 > on every candidate?  This might require changing the data structure,
 > for example, to an alist like is returned by `seq-group-by`.

One could return a cons of the transformed candidate and the title, but 
this has the downside that you always compute/allocate the transformed 
candidate. It is better to perform the candidate transformation lazily 
only for the candidates which are actually displayed. This is similar to 
the computation of annotations/affixations, which are only computed 
lazily if the completion UI displays only a subset of the actual candidates.

Dmitry, Stefan and I discussed multiple possible incarnations of such a 
group-function functionality 
(https://github.com/minad/consult/issues/283). The current solution 
turned out to be an efficient and simple solution. We also discussed 
solutions which avoided multiple function calls for every candidate, but 
these were more complex. Note that I am using group functions heavily in 
my Consult package with the design proposed here.

 > Another variant is to put additional text properties on candidate 
strings,
 > e.g. a text property on redundant prefix with the group title that
 > completion--insert-strings then could fetch from the input string.
Yes, this would be possible, but it would be a less flexible design. I 
followed the design of the annotation/affixation-functions for this. I 
also like about the design that it is somehow "pluggable", you add the 
group-function and you can augment your completion table with grouping 
without having to do other adjustments to how the candidates are 
generated. (Note that you may still want to attach a title property to 
the candidates to ensure that the transform=nil call is fast and 
non-allocating, as I did in the xref modifications in this patch.)

Daniel



  reply	other threads:[~2021-04-25 21:26 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-25 13:32 [PATCH] `completing-read`: Add `group-function` support to completion metadata Daniel Mendler
2021-04-25 19:35 ` Dmitry Gutov
2021-04-25 19:47   ` Daniel Mendler
2021-04-25 21:50     ` Dmitry Gutov
2021-04-25 22:10       ` Daniel Mendler
2021-04-25 22:40         ` Dmitry Gutov
2021-04-25 22:58           ` Daniel Mendler
2021-04-26  4:51             ` Protesilaos Stavrou
2021-04-27 16:53               ` Juri Linkov
2021-04-28  6:18                 ` Protesilaos Stavrou
2021-04-25 23:33           ` Stefan Monnier
2021-04-26 10:01             ` Daniel Mendler
2021-04-26 13:50               ` Stefan Monnier
2021-04-27  1:46             ` Dmitry Gutov
2021-04-27  1:59               ` tumashu
2021-04-27  2:45                 ` Daniel Mendler
2021-04-27 15:47                 ` Dmitry Gutov
2021-04-27  3:41               ` Stefan Monnier
2021-04-28  0:08                 ` Dmitry Gutov
2021-04-28  3:21                   ` Stefan Monnier
2021-04-25 19:38 ` [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH) Daniel Mendler
2021-04-25 20:45   ` Juri Linkov
2021-04-25 21:26     ` Daniel Mendler [this message]
2021-04-29 16:20   ` Juri Linkov
2021-04-29 16:52     ` Daniel Mendler
2021-04-29 17:07     ` Stefan Monnier
2021-04-29 17:13       ` Daniel Mendler
2021-04-29 22:54         ` Juri Linkov
2021-04-29 23:55           ` [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH VERSION 2) Daniel Mendler
2021-04-30  9:00             ` Daniel Mendler
2021-04-30 17:01               ` Juri Linkov
2021-04-30 18:11                 ` Daniel Mendler
2021-04-30 18:30                   ` Daniel Mendler
2021-05-01 19:57                     ` Juri Linkov
2021-05-02  0:43                       ` Daniel Mendler
2021-05-02  7:07                         ` Eli Zaretskii
2021-05-02 11:01                           ` Daniel Mendler
2021-04-30 16:51             ` Juri Linkov
2021-04-30 18:13               ` Daniel Mendler
2021-05-01 19:54                 ` Juri Linkov
2021-05-02  0:32                   ` Daniel Mendler
2021-05-02 21:38                     ` Juri Linkov
2021-05-07 17:03                       ` Juri Linkov
2021-05-07 17:55                         ` Daniel Mendler
2021-05-08  6:24                           ` Daniel Mendler
2021-05-08  8:45                             ` [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH VERSION 4) Daniel Mendler
2021-05-08  9:10                               ` Daniel Mendler
2021-05-09 17:59                                 ` Juri Linkov
2021-05-09 18:50                                   ` Daniel Mendler
2021-05-09 18:56                                     ` Stefan Monnier
2021-05-09 19:11                                       ` Daniel Mendler
2021-05-10 20:47                                     ` Juri Linkov
2021-05-11  7:51                                       ` [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH VERSION 5) Daniel Mendler
2021-05-11 17:59                                         ` Juri Linkov
2021-05-08 13:15                         ` [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH VERSION 2) Stefan Monnier
2021-05-09 18:05                           ` Juri Linkov
2021-05-09 18:37                             ` Eli Zaretskii
2021-05-11 18:06                               ` Juri Linkov
2021-05-11 18:44                                 ` Eli Zaretskii
2021-05-11 18:58                                   ` Daniel Mendler
2021-05-11 19:22                                     ` Eli Zaretskii
2021-05-11 19:46                                       ` Daniel Mendler
2021-05-11 19:59                                         ` Eli Zaretskii
2021-05-11 20:30                                           ` [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH VERSION 6) Daniel Mendler
2021-05-13 10:32                                             ` Eli Zaretskii
2021-05-13 11:45                                               ` [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH VERSION 7) Daniel Mendler
2021-05-20  9:39                                                 ` Daniel Mendler
2021-05-20 17:53                                                   ` Juri Linkov
2021-05-20 18:51                                                     ` Daniel Mendler
2021-04-29 17:09     ` [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH) Dmitry Gutov
2021-04-29 17:16       ` Daniel Mendler
2021-04-29 17:55         ` Dmitry Gutov
2021-04-29 18:31           ` [External] : " Drew Adams
2021-04-29 20:25             ` Dmitry Gutov
2021-04-29 22:15               ` Drew Adams
2021-04-29 22:28                 ` Dmitry Gutov
2021-04-29 23:31                   ` Drew Adams
2021-04-29 19:21           ` Daniel Mendler
2021-05-02 14:29   ` [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH VERSION 3) Daniel Mendler
2021-05-02 21:49     ` Juri Linkov
2021-05-03 14:40       ` Daniel Mendler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4d9971af-9af1-97a6-61fc-d88d4d192dcc@daniel-mendler.de \
    --to=mail@daniel-mendler.de \
    --cc=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=gregory@heytings.org \
    --cc=juri@linkov.net \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).