Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Rakudo Perl 6 and MoarVM Performance Advances

by raiph (Deacon)
on Aug 23, 2014 at 03:56 UTC ( #1098390=perlnews: print w/replies, xml ) Need Help??

This post is about the immature Perl 6, not the rock solid Perl 5

Jonathan Worthington has just delivered a presentation at YAPC::EU discussing Rakudo performance work over the last 12 months. There's a video of the talk and slides.

The presentation includes a look at benchmarks comparing a recent Rakudo (on MoarVM) with the 2013.08 release of Rakudo (on Parrot) and Perl 5 v20. I'm curious what folk make of the numbers on page 76.

He also revealed a new profiling tool. Update: Here it is profiling some P6 code.

If any readers have tried Perl 6 but found it too slow, now might be a good time to try again; you should find that it's a lot faster than it was, and if it isn't fast enough for your use case it's now a lot easier to both see what's making it slow and to make it faster.

  • Comment on Rakudo Perl 6 and MoarVM Performance Advances

Replies are listed 'Best First'.
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.

      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.

      .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.

        Results for a similar 19MB log file on my 2013 Macbook Pro:

        Perl 5: 0.68 secs
        Perl 6/Grammar: 49.8 secs

        so 73 times slower.

      FWIW, perl6 -ne 'say ~$0 if m/(<<\w**5>>)/' is much faster. Something likely needs to be optimized in Match.gist. It's still much slower than Perl 5

        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'

      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.

        Perl 6 now 2 mins. 20 seconds. For the record Ruby 2.1:

        ruby -wnl -e 'puts $1 if /\b(\w{5})\b/' logs.txt

        ... completed in 2 seconds.

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlnews [id://1098390]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2023-02-05 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (31 votes). Check out past polls.

    Notices?