unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Tianxiang Xiong <tianxiang.xiong@gmail.com>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Performance issue w/ `cl-loop`s `collect...into`
Date: Sun, 08 Apr 2018 22:20:21 -0400	[thread overview]
Message-ID: <jwv1sfp86n0.fsf-monnier+Inbox@gnu.org> (raw)
In-Reply-To: <CACMkxixs32_UW2m+Grmbm9s=ZVyEf3Mi==qwqNaC1i39rc=j1w@mail.gmail.com> (Tianxiang Xiong's message of "Sun, 8 Apr 2018 19:16:08 -0700")

> IIUC the `(eq var cl--loop-accum-var)` is used to test whether the
> accumulation is `into` or not. If not, clauses like `collect(ing)` use a
> `cons-nreverse` rather than `nconc` algorithm, which is O(n) instead of
> O(n^2). Since we're doing `setcdr` in all cases where the accumulation is
> into a list, we're always O(n), so the optimization is unnecessary.

I agree that the algorithmic complexity of "cons+nreverse" is no better
than that of the setcdr, but that doesn't mean that it's the same speed.
Since (eq var cl--loop-accum-var) is expected to be the most common
case, it'd be good to make sure that your patch doesn't make the
code slower, hence the need to test the performance.


        Stefan


> Attached is a new patch that uses `(cl--loop-accum-var)`.
>
> On Sun, Apr 8, 2018 at 6:59 PM, Stefan Monnier <monnier@iro.umontreal.ca>
> wrote:
>
>> > Here's a second, cleaner attempt that separates the
>> `cl--loop-handle-accum`
>> > function into two functions, one to deal with lists and one to deal w/
>> > non-lists.
>> > The tail-tracking optimizing is also applied to `append(ing)` and
>> > `nconc(ing)`.
>>
>> Thanks.  Looks good.
>> I see you've dropped the (eq var cl--loop-accum-var) optimization.
>> Have you tried to measure the effect?
>>
>>
>>         Stefan
>>
>>
>> > +(defun cl--loop-handle-accum (def)
>> [...]
>> > +  (cond
>> [...]
>> > +    (cl--loop-accum-var cl--loop-accum-var)
>>
>> You can write this line as just
>>
>>        (cl--loop-accum-var)
>>
>>
>> -- Stefan
>>
>>
>>



  reply	other threads:[~2018-04-09  2:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-08  0:51 Performance issue w/ `cl-loop`s `collect...into` Tianxiang Xiong
2018-04-08  3:26 ` Clément Pit-Claudel
2018-04-08  5:56   ` Tianxiang Xiong
2018-04-08  6:12     ` Clément Pit-Claudel
2018-04-08  8:50       ` Tianxiang Xiong
2018-04-08 13:19         ` Clément Pit-Claudel
2018-04-08 16:07         ` Stefan Monnier
2018-04-08 19:58           ` Tianxiang Xiong
2018-04-08 21:13             ` Stefan Monnier
2018-04-08 23:29               ` Tianxiang Xiong
2018-04-09  1:10                 ` Tianxiang Xiong
2018-04-09  1:59                   ` Stefan Monnier
2018-04-09  2:16                     ` Tianxiang Xiong
2018-04-09  2:20                       ` Stefan Monnier [this message]
2018-04-09  3:34                         ` Tianxiang Xiong
2018-04-09  3:38                           ` Tianxiang Xiong
2018-04-09 12:07                           ` Stefan Monnier
2018-04-09 12:22                           ` Basil L. Contovounesios
2018-04-09 15:28                             ` Tianxiang Xiong
2018-04-09 15:33                               ` Tianxiang Xiong
2018-04-14  7:01                                 ` Tianxiang Xiong

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=jwv1sfp86n0.fsf-monnier+Inbox@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=tianxiang.xiong@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 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).