Thursday, August 6, 2009

Stumbling with Rakudo

As has become my habit, yesterday when I needed a small Perl script for work, I tried coding it in Perl 6. IMO, the resulting script is beautiful. I think it's more a shifting of what I consider the common idiom than an actual difference in the languages, but using when instead of the single-line modifier form of if really makes me happy. (Yes, I know when is available in 5.10, but that's not the idiom I'm comfortable using in Perl 5.)

There's only one problem: this isn't actually usable in Rakudo yet. I might have the $*IN part incorrect, but I changed it to use a filehandle for input and print out each line of the file it read during the for loop. And when I ran it on the 10 meg data file I needed to analyze, it just sat there. I believe it was probably trying to read the entire file before doing anything with it, as laziness isn't implemented yet. Between that and Rakudo's lack of speed, the script was a no-go, and I ended up rewriting the script in Perl 5.

PS Before actually posting this, I actually ran the Perl 6 version to completion and timed it. 88 minutes. That's versus less than a second for the Perl 5 version. In fact, I actually wrote and executed the Perl 5 version in considerably less time than it would have taken to just run the Perl 6 version. Also (as sharp eyes may have noticed), I forgot that spaces in regexes are ignored in Perl 6, so the Perl 6 version was in fact incorrect. Getting a working version would have required at least another 88 minutes of sitting there....


  1. Did you at least find where it was slow? That would be useful information.

  2. I'm not sure how to do a proper profile on Perl 6 code, but I'm pretty sure the call to "lines" is taking a relatively huge amount of time before it comes back with anything.

  3. Sadly Rakudo is not yet to the optimization phase... "Premature optimization is the root of all evil" and all that.

    I tried doing some file processing in Rakudo the other day with $fh.get() (line-at-a-time), and even then it was fairly slow.

    That said, Rakudo Star is planned for release in early 2010 ("Spring"), and speed is a high priority for the release - have a look at the Rakudo ROADMAP doc in docs/ROADMAP in the github repo.