emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pattern matching on match-string groups #elisp #question


From: Mattias Engdegård
Subject: Re: Pattern matching on match-string groups #elisp #question
Date: Sun, 28 Feb 2021 14:46:42 +0100

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]