all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dmitry@gutov.dev>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: Yuri Khan <yuri.v.khan@gmail.com>, Eli Zaretskii <eliz@gnu.org>,
	John Wiegley <jwiegley@gmail.com>,
	emacs-devel@gnu.org
Subject: Re: master 4b79c80c999 1/2: New function 'sort-on'
Date: Sat, 2 Mar 2024 01:37:01 +0200	[thread overview]
Message-ID: <8b31204f-4e8c-4c56-bbc7-73c9bfabb651@gutov.dev> (raw)
In-Reply-To: <87zfvldokn.fsf@web.de>

On 28/02/2024 09:40, Michael Heerdegen wrote:
> Dmitry Gutov <dmitry@gutov.dev> writes:
> 
>> The other alternative (suggested by Daniel) is to add a yet another
>> optional argument - whether to do the schwartz transform - so it would
>> be on the caller to determine whether the accessor is costly enough.
> 
> This would be my preferred solution, too
> 
>> This is not my first choice, but I'd still prefer it over having two
>> different but very similar functions. sort-on is slower than it has to
>> be, too.
> 
> It could be improved?  How?

Well, 'mapcar' in it allocates a new sequence of length N. The Schwartz 
transform creates about as many new cons cells too. If the function is 
made destructive, 'mapcar' becomes unnecessary as the original sequence 
could be reused - and that is measurably faster, too (when the cost 
function is simple enough).

And if it's made destructive, it becomes even closer to the current 
'sort'. That would mean less justification to keep them as separate 
functions.

> BTW, I wonder how this addition fits into my original suggestion about
> sort predicate construction.

Sorry, I either can't find your respective message in this thread, or 
don't understand the suggestion.

> I guess we would want to allow to choose
> between using schwartz or not (at each level) in the specification -

I don't know if we really want to (every such knob is a step toward more 
complex api, and higher odds of user choosing the parameters poorly), 
but we could indeed try something like that.

> which would mean that my approach would build a sort function, not a
> sort predicate.  Which also might allow to build more efficient code.

If you mean that your proposed constructed sort function would 
incorporate the lookup logic (currently supplied with ACCESSOR), then it 
would incur the same cost that the Schwartz transform is amortizing, 
wouldn't it? Perhaps some code would help.

Also, if the sort function will be in Lisp (even byte-compiled one), 
then it will likely have higher overhead than the simple '< or 'string<, 
for example. And while the cost of the transform is O(N), the comparison 
function is called O(N*logN) on average.



  reply	other threads:[~2024-03-01 23:37 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <170688047526.14693.2994051491358257471@vcs2.savannah.gnu.org>
     [not found] ` <20240202132756.4272CC0EFE7@vcs2.savannah.gnu.org>
2024-02-02 15:00   ` master 4b79c80c999 1/2: New function 'sort-on' Daniel Mendler via Emacs development discussions.
2024-02-02 15:04     ` Eli Zaretskii
2024-02-02 15:26       ` Daniel Mendler via Emacs development discussions.
2024-02-02 15:47         ` Eli Zaretskii
2024-02-02 16:05           ` Daniel Mendler via Emacs development discussions.
2024-02-05 12:14             ` Michael Heerdegen
2024-02-02 15:55         ` Dmitry Gutov
2024-02-02 15:30       ` Michael Heerdegen via Emacs development discussions.
2024-02-02 15:35         ` Daniel Mendler via Emacs development discussions.
2024-02-02 16:08           ` Michael Heerdegen via Emacs development discussions.
2024-02-02 16:23             ` Daniel Mendler via Emacs development discussions.
2024-02-02 16:43               ` Michael Heerdegen via Emacs development discussions.
2024-02-02 15:50         ` Eli Zaretskii
2024-02-02 16:06           ` Eshel Yaron
2024-02-02 16:34             ` Eli Zaretskii
2024-02-02 16:46           ` Michael Heerdegen via Emacs development discussions.
2024-02-02 17:55             ` Emanuel Berg
2024-02-05  0:48           ` Dmitry Gutov
2024-02-05  5:30             ` Yuri Khan
2024-02-05 12:52               ` Eli Zaretskii
2024-02-05 13:25               ` Dmitry Gutov
2024-02-05 14:31                 ` Eli Zaretskii
2024-02-05 14:47                   ` Dmitry Gutov
2024-02-05 15:10                     ` Eli Zaretskii
2024-02-05 15:29                       ` Dmitry Gutov
2024-02-28  7:40                 ` Michael Heerdegen
2024-03-01 23:37                   ` Dmitry Gutov [this message]
2024-03-04  6:45                     ` Michael Heerdegen
2024-03-04 16:43                       ` Dmitry Gutov
2024-03-05  8:06                         ` Michael Heerdegen
2024-03-05 10:21                           ` Michael Heerdegen via Emacs development discussions.
2024-03-05 12:39                             ` Eli Zaretskii
2024-03-06  3:20                               ` Michael Heerdegen
2024-03-06 12:10                                 ` Eli Zaretskii
2024-03-06 18:34                                   ` Dmitry Gutov
2024-03-06 20:12                                     ` John Wiegley
2024-03-07  1:34                                       ` Dmitry Gutov
2024-03-05 12:44                             ` Dmitry Gutov

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

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

  git send-email \
    --in-reply-to=8b31204f-4e8c-4c56-bbc7-73c9bfabb651@gutov.dev \
    --to=dmitry@gutov.dev \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=jwiegley@gmail.com \
    --cc=michael_heerdegen@web.de \
    --cc=yuri.v.khan@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.