New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grep {/PATTERN/} is slow #7579
Comments
From @AbigailCreated by @AbigailI would expect grep {EXPR} LIST to be somewhat slower than grep EXPR, LIST For instance, the following benchmark shows the block version to use Benchmark qw /cmpthese/; our @array = 101 .. 200; cmpthese -2 => { __END__ If, however, the expression is a regexp, things change drastically: use Benchmark qw /cmpthese/; our @array = 101 .. 200; cmpthese -2 => { __END__ This difference in speed surprises me. It's not the fact that it's a regexp that's run inside a block, use Benchmark qw /cmpthese/; our @array = 101 .. 200; cmpthese -2 => { __END__ use Benchmark qw /cmpthese/; our @array = 101 .. 200; cmpthese -2 => { __END__ In both cases, the block version is slower, but by a small margin. So, I suspect a bug somewhere. I'll be leaving for my honeymoon and YAPC::AU tomorrow morning, so it might Abigail Perl Info
|
From tassilo.von.parseval@rwth-aachen.deOn Thu, Nov 04, 2004 at 11:55:31PM +0000 abigail@abigail.nl (via RT) wrote:
[...] Just for the record: I can confirm this. The problem is still in blead Tassilo |
The RT System itself - Status changed from 'new' to 'open' |
From ajs@ajs.comI've tried this with 5.6.1, 5.8.3 and 5.8.5, all with the same result. I |
From ajs@ajs.comSorry, I submitted before I was done. My final version of the test: use Benchmark qw /cmpthese/; our @array = 101 .. 20000; cmpthese -2 => { die unless $b1 == $b2; sub is50 { I also tried: our and then something like: grep_re_blck => '$::b1 = grep {/$p/} @::array', which was very slightly faster (relative to the expr version with the |
From @HugmeirOn Fri Dec 03 11:22:39 2004, ajs wrote:
This is still present in blead; But as far as I can tell, the slowdown |
From @cpansproutOn Sun Apr 29 18:49:32 2012, Hugmeir wrote:
But the enter/leave shouldn’t make this much difference: The first script, which uses $_==50: $ pbpaste|perl5.15.9 The second script, which uses /^50$/: $ pbpaste|perl5.15.9 -- Father Chrysostomos |
From @epaSome say that grep { /PATTERN } @x is better style than grep /PATTERN/, @x (Perl Best Practices and perlcritic BuiltinFunctions::RequireBlockGrep) To keep these people happy it would be good to put in an optimization for the If speeding it up is a WONTFIX, then perhaps perlcritic's rules need to change. -- |
From @nwc10On Tue, May 01, 2012 at 10:48:53AM +0000, Ed Avis wrote:
It is a safe general-case transformation? Is there any behaviour one can $ perl -MO=Concise,-exec -e 'grep /PATTERN/, @x' $ perl -MO=Concise,-exec -e 'grep {/PATTERN/} @x' The idea of an optimisation seems nice. But I don't know if it's trivially Nicholas Clark |
From @iabynOn Tue, May 01, 2012 at 10:48:53AM +0000, Ed Avis wrote:
It definitely isn't yet a WONTFIX: there's something specifically about Until the reason is diagnosed, we can't really decide what to do about -- |
From @AbigailOn Tue, May 01, 2012 at 04:14:12AM -0700, Dave Mitchell via RT wrote:
Note that the slowdown isn't a "regexp in a block". It's a With map, I get an inbetween value (using 5.15.9): use Benchmark qw /cmpthese/; our @array = 1 .. 200; cmpthese -2 => { __END__ Also, if the matches are failing, the difference between grep-block use Benchmark qw /cmpthese/; our @array1 = 5000 .. 5099; cmpthese -2 => { __END__
The bug is quite old (I've known about it for longer than the bug report Abigail |
As @nwc observed, with
With
Using the wrapper of
and this for the second:
A good chunk of the extra runtime seems to be due to Neither of
vs:
|
The SV for which the mortal copy is being made is |
Using Abigail's benchmark against blead, things look tighter than they used to be:
#20800 would still help a lot:
The remaining overhead then seems down to the |
vs
I don't know why the difference in the LINESEQs... |
(Updated from original comment which suggested that it was set by the parser.) The flag seems to be set by
Commenting out that line does allow miniperl to produce a simpler OP tree for
but perl then won't build:
Maybe someone more familiar with the regex engine would be able to figure out if there are circumstances in which |
Migrated from rt.perl.org#32331 (status was 'open')
Searchable as RT32331$
The text was updated successfully, but these errors were encountered: