2015.11 Native arrays arrive

Friday the Thirteenth turned out to be a very fruitful day, as jnthn++ could finally merge a lot of the work that he has been doing the past weeks in the background regarding native arrays. Native integer arrays come in the following flavours: int8, uint8 (one byte per element), int16, uint16 (two bytes per element), int32, uint32 (four bytes per element), and int64, uint64 (eight bytes per element). On top of that there are two generic native integer array types: int and uint, which are aliases for either the 32bit or 64bit version (depending on your hardware and/or build options). So what does that mean for performance in e.g. filling a 10M element array with an integer value:

my Int @A; my int $i;
while $i < 10000000 { @A[$i] = 1; $i = $i + 1 }   # 11.6 CPU seconds

Using an int array is more than 11x faster:

my int @a; my int $i;
while $i < 10000000 { @a[$i] = 1; $i = $i + 1 }   #  1.0 CPU seconds

If we compare this to Perl 5, we can see that Perl 5 is slower in this particular benchmark:

use integer;
my @a; my $i = 0;
while ($i < 10000000) { $a[$i] = 1; $i = $i + 1 } #  1.5 CPU seconds

However, Perl 5 optimizes the for idiom much better than using while. So if we use the for idiom, we get:

use integer;
my @a;
for (0 .. 9999999) { $a[$_] = 1 }             # 1.0 CPU seconds

So on par with Perl 5. Still, it is very exciting to see Perl 6 execution speeds approaching Perl 5’s!

Apart from native integer arrays, we also now have native numeric (real) arrays in 2 flavours: num32 (4 bytes) and num64 (8 bytes), and a generic num type that aliases to either.

The native arrays implementation is still a bit rough on the edges, specifically with regards to Listy functions such as .pick, .roll etc. The reason why these do not work yet, is clear: there is still some discussion as to how to resolve the issue, as it will involve some internal code shuffling.

Why is it so hard?

moritz++ wrote a very interesting blog post about why it is so hard to write a compiler for Perl 6. There were quite some comments on Reddit.

TheDamian in Amsterdam

Damian Conway gave his Everyday Perl 6 presentation in Amsterdam last week (like he did in Oslo the week before that). Some photo impressions from the lovely ambiance of the Tuschinski Theater. To quote TheDamian:

Perl 6 is a computer scientist’s dream come true. Its many advanced features (junctions, multiple dispatch, generics, delegation, grammars, lazy evaluation, infinite lists, hyperoperators, first class functions, coroutines, partial function application, macros, metadata, etc., etc.) offer the elite überhacker entirely new levels of awesome cosmic power.

Unfortunately, for the majority of us, those incredible new features are mostly just mysterious, scary, and off-putting. But all of those new features are also entirely optional. You don’t have to start out in Perl 6 writing autoparallelized infinite superpositions of multimorphic higher-order functions. You don’t even have to statically type your variables or encapsulate your objects.

Using attributes in regexes

jnthn++ added a compile time error when using class attributes inside a regex. From the commit message:

Regexes are methods on Cursor (or some subclass of it), meaning that
an attribute access inside of them is relative to that. Rather than
failing silently or exploding noisily at runtime, catch the problem at
compile time. The typed exception’s message explains the issue and
offers a suggestion.

Development Allsorts

  • FROGGS++ fixed a long standing bug on the JVM backend involving our scoped subs in combination with precompilation. This now allows e.g. the URI module to be used on the JVM backend.
  • hoelzro++ found a problem when multiple readers read from the same Channel. lizmat++ fixed this (at least for now) and hoelzro added a test for it.
  • lizmat kebab-cased some functionality (and added deprecations for the old names) in an effort to provide more naming consistency: is hidden-from-backtrace, is hidden-from-USAGE, use MONKEY-TYPING, RAKUDO-NO-DEPRECATIONS, Supply.on-demand, Supply.schedule-on.
  • If you’re running spectests regularly, you will see quite an increase in number of tests (36600+ tests now): these are mostly new native array tests.

Winding Down

timotimo++ was not feeling well enough yet to do the Perl 6 Weekly, so yours truly did it this time. timotimo, get and feel better soon!

Please let me know of any errors, comments, suggestions, like always!


Got something to note?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s