Re: Rakudo Perl 6 and MoarVM Performance Advances
by gunzip (Monk) on Sep 05, 2014 at 02:23 UTC
|
On OSX 10.8 with Perl 5.16 and Perl6/MoarVM 2014.08 I ran these one-liners against a 17Mb Apache log file:
perl -wnl -E 'say $1 if /\b(\w{5})\b/' logs.txt
perl6 -n -e 'say $0 if ~~ m/(<<\w**5>>)/' logs.txt
Perl 5 took 1.2 seconds and Perl6 2mins. 49 seconds so I'm not confident that Perl6 will ever be anywhere near Perl 5 for common use cases such as this.
| [reply] [d/l] [select] |
|
I'm not confident that Perl6 will ever be anywhere near Perl 5 for common use cases such as this.
In Perl 5 regular expressions are handled by an ad-hoc, highly-optimized matcher (it's like a different interpreter). In Perl 6 (well, Rakudo, actually) I believe they are just compiled into regular "bytecode" which is then executed by the virtual machine as any other perl 6 code.
Perl 6 approach is much more generic and powerful but it would take a while until all the involved layers get as fast as the ad-hoc perl5 matcher. In the worst case, Rakudo could just fall-back to the perl 5 approach for simple regular expressions.
| [reply] |
|
.lines() and -n are really really slow in rakudo, the code behind that is not really clever, compared to the code in Perl 5 (there is a talk by leont about what P5 does there).
This should be better:
perl6 -e 'grammar G { token TOP { <line>* }; token line { \N*\n } }; class A { method line($m) { say ~$0 if $m ~~ m/(<<\w**5>>)/ } }; G.parse(slurp(), :actions(A))'
If tested that on a file from my box, result:
Perl 5: 0.2s
Perl 6: 6.2s
That would mean that it might take about 45s on your box... can you verify that?
Note 1) String handling is the slowest part in rakudo atm.
Note 2) You should not compare printing the .gist of a match to a string from another language. Because Date::Dumper-ing an object in P5 is not really fast either. And that is what .gist somewhat is. (.gist is the human friendly nice formatted version of Data::Dumper aka method .perl)
Note 3) I promised to look into the cheats P5 does when walking over lines, and I'll do that this weekend.
| [reply] [d/l] |
|
| [reply] |
|
|
| [reply] [d/l] [select] |
|
Additionally, appending for lines gives a significant gain over using -n, so that needs works as well.
EDIT: I agree that '-n' should be what is used here, I was moreso posting in the interest of figuring out why that's so slow. I just made a PR which seems to bring the time for '-n' to be more like that of 'for lines'
| [reply] [d/l] [select] |
|
|
|
That's not great indeed. I don't really hope this will make much of a difference, but you did not have to capture the match with parenthesis. You could have just used $/:
perl6 -n -e 'say $/ if m/<<\w**5>>/' logs.txt
On the other hand, even if this does make a difference, the optimizer should have converted it automatically.
| [reply] [d/l] |
|
| [reply] [d/l] |
Re: Rakudo Perl 6 and MoarVM Performance Advances
by Laurent_R (Canon) on Aug 23, 2014 at 09:04 UTC
|
Thank you very much, raiph, for sharing this very interesting information. It looks like we're still not really quite there, but have made a pretty large part of the way toward it.
| [reply] |
|
| [reply] |