From: "Mattias Engdegård" <mattiase@acm.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
Ag Ibragimov <agzam.ibragimov@gmail.com>,
Emacs developers <emacs-devel@gnu.org>
Subject: Re: Pattern matching on match-string groups #elisp #question
Date: Sun, 28 Feb 2021 14:46:42 +0100 [thread overview]
Message-ID: <62A88DEE-5BFD-4479-AB15-1A43DC2B299D@acm.org> (raw)
In-Reply-To: <jwveeh16zhu.fsf-monnier+emacs@gnu.org>
27 feb. 2021 kl. 21.32 skrev Stefan Monnier <monnier@iro.umontreal.ca>:
>> So where does that leave us with the rx pattern?
>
> It doesn't affect it directly, except in the fact that the old
> definition would now also work for `pcase-let`.
Well, the new rx definition is now in place since the old one, and the even older one in Emacs 26 and earlier, were buggy as you showed. This means that the 'rx' pattern no longer relies on side-effects being retained in pcase.
I went with dotted lists (a b c . d) because benchmarking showed it to be faster than either proper lists or vectors, the generated code is smaller than for lists, and the case of a single variable reduces naturally to no consing at all.
>> I now have, and am sad to say that a list is always faster for any practical
>> number of N (I didn't bother trying more than 30) although the difference
>> narrows as N grows. This is despite the destructuring code becoming
>> considerably bigger for lists (as we get a long chain of tests and branches)
>> than for vectors. It all boils down to vector construction being more
>> expensive than lists.
>
> Indeed, I think there's some optimization opportunities in our
> implementation of vector construction. We've already improved the
> performance significantly compared to Emacs<24, but there's still room
> for improvement.
Looking a bit closer it gets more nuanced: one reason why
(pcase (list 1 2 3) (`(,a ,b ,c) (+ a b c)))
is faster than
(pcase (vector 1 2 3) (`[,a ,b ,c] (+ a b c)))
is that the latter contains three general function calls: to `vector`, `vectorp`, and `eql` (for checking the length), whereas the list version has byte-ops for everything.
next prev parent reply other threads:[~2021-02-28 13:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-25 5:11 Pattern matching on match-string groups #elisp #question Ag Ibragimov
2021-02-25 14:55 ` Basil L. Contovounesios
2021-02-25 15:32 ` Stefan Monnier
2021-02-25 18:28 ` Mattias Engdegård
2021-02-26 4:31 ` Stefan Monnier
2021-02-26 10:24 ` Mattias Engdegård
2021-02-26 19:38 ` Stefan Monnier
2021-02-27 10:17 ` Mattias Engdegård
2021-02-27 14:39 ` Stefan Monnier
2021-02-27 18:10 ` Mattias Engdegård
2021-02-27 20:32 ` Stefan Monnier
2021-02-28 13:46 ` Mattias Engdegård [this message]
2021-02-28 15:37 ` Stefan Monnier
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=62A88DEE-5BFD-4479-AB15-1A43DC2B299D@acm.org \
--to=mattiase@acm.org \
--cc=agzam.ibragimov@gmail.com \
--cc=contovob@tcd.ie \
--cc=emacs-devel@gnu.org \
--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 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.