Jonathan Leto: June 2009 Archives

GSoC Bird of Feather Session at OpenSourceBridge

| | TrackBacks (0)

The first day of OpenSourceBridge was amazing and we finished it off by having a Bird of Feather session for people involved and/or interested in Google Summer of Code.

gsoc_bof_osbridge1.jpgI know that it was very helpful to hear and talk about how the current GSoC is going with my fellow organization admins, mentors and students. Cat Allman, Ellen Ko and Leslie Hawthorn contributed a lot of knowledge and experience about how to deal with things when they go pear-shaped, and I even met an organization and mentor that are my neighbors! Some of the great ideas that came out of this were that first-year organizations would be greatly helped by having a "buddy" organization that has been involved in GSoC before, so that a brand-new organization admin can have a friendly ear to bend when they need help. I mentioned this because I usually bend Bart Massey's ear when I need some GSoC guidance, and I thought that other first-year admins could also greatly benefit from something like this.

I was a mentor for the The Perl Foundation last year, with the Math::GSL project and this year I find myself the organization admin as well as a mentor for the Math::Primality project, which implements advanced prime-checking algorithms for Perl 5. It is definitely a big step to go from mentor to admin and meeting up with people in the same situation really helps!

I will definitely be going to OpenSourceBridge next year and hope that we have a GSoC meetup there again.

Google Summer of Code Updates

| | TrackBacks (0)
If all the dates and timelines of Google Summer of Code have you confused, this nice color-coded visualization of each part of the summer may help make it more sense.

Next week is the super-cool-with-extra-awesomesauce conference Open Source Bridge, which is all about being an "open source citizen." ( I recently had to explain to someone that it was not an "Open Sores Conference". Much hilarity ensued) . There will be many open source folk from around to globe, including many GSoC mentors, students and the program manager, Leslie Hawthorn. This prompted me to create a Bird of Feather session for GSoC people. This is for anybody that has every been part of GSoC or is interested in participating in the future. Come on by and hang out!

As always, you can find us in #soc-help on if you want to get involved.

The Perl Foundation GSoC2009 Roundup

| | TrackBacks (0)
So much has been going on this summer of code! As a recap, TPF got nine student slots this year, which means we have nine mentors and nine students working on various things this summer. Here is a sample of what has been going on recently.

Pascal Gaudette describes his love for debugging tricky HTTP/1.1 issues in Mojo
and has even added a "featurette."  Devin Austin has been talking about
eviscerating Catalyst::Helper and Daniel Arbelo Arrocha has thoughtfully
detailed the difference between bonding and bondage. My student, Robert Kuo,
has been busy reading the mathematical paper and example C implementation  of
the Strong Lucas Pseudoprime primality test for Math::Primality . While installing Math::GMPz, which we use to access the GNU Multiprecision Library (GMP), he found a small issue which caused some test failures and submitted a bug report.

Math::Primality also very recently gained a working is_prime() method, which
works for arbitrary sized integers, due mostly to Robert Kuo's implementation
of is_strong_lucas_psuedoprime() being finished. Now you can test for prime numbers in Perl without installing Math::Pari! More about this in a separate post!

Ryan Jendoubi is working on a Perl interface for wxWebkit and Hinrik Örn Sigurðsson
is working on the command line utility to read Perl 6 documentation called grok.
Justin Hunter has been hacking on his blogging software so that he can blog about
his work on SQL::Translator. Sometimes it's a vicious cycle...

Back to hacking on some code!

To use less memory! You may think that

my $x = 'foo'; my $y = $x;

would store the string 'foo' in one place, and then when $y gets changed, use the new string. It doesn't. To see this, we can use Devel::Peek from the perl debugger. We start it up with

perl -de0

which I have aliased to p in vim, because yes, I am that lazy and I loves me some debugger. Once we are in the debugger you have to use the module. Note that the debugger output is bolded.

 DB<1> use Devel::Peek

Then define a variable

 DB<2> $x = 'foo'

PROTIP: You can't use my $x in the interactive debugger because each line of input to the debugger gets wrapped in it's own lexical scope, a lexical variable (i.e one defined with my) will not exist outside of this inner scope.

Now we use the "x" debugger command, which prints out the result of executing some Perl code. We give it the code Dump $x, which calls Devel::Peek's Dump method on $x, which prints out low-level information about the internal properites of a variable.

 DB<3> x Dump $x
SV = PV(0x9542ca4) at 0x9565924
 PV = 0x95731b8 "foo"\0
 CUR = 3
 LEN = 4
 empty array

SV is Perl-internals-speak for "scalar value" and the PV means that it is a string. The reference count is 1, which means only one thing, itself, points to itself. When a variable goes out of scope, the REFCNT goes to 0 and the Perl garbage collector recycles it. The FLAGS containing POK tells us that is a valid string. Take note that the PV line shows us the memory address that the string is stored at, as well as it's value and that it is null-terminated.

Now let's set a new variable equal to $x.

 DB<4> $y = $x

Now let's take a look at it:

 DB<5> x Dump $y
SV = PV(0x9542c2c) at 0x958ab70
 PV = 0x958b968 "foo"\0
 CUR = 3
 LEN = 4
 empty array

The PV line is the most interesting. If you compare it to above, you will see that it is a different memory address! Not just the overhead of each Perl variable is being stored, but the string 'foo' is being stored in two different places!

Now imagine that our string is a few hundred megabytes, and you are manipulating it. You are really going to notice having a few extra copies of it around, aren't you! If you know that you have a lot of data structures that have the same string in them, use a reference to save memory. If you are running up against "perl Out of memory!", this could be a trick that gets you out of that bind without buying more RAM.

Let's check out the memory savings with Devel::Size, a nice module which can tell you how much memory your Perl variables are using.
DB<1> use Devel::Size qw/size total_size/              

Next we create a longish string.

DB<2> $x = 'i like eating memory' x 1000                                

We can use the size() function to see how much memory it is using:

DB<3> x size($x)                                                                                           
0  20036

Now let us dump a hash which has this string repeated as two values. We use the total_size() function, which follows references:

DB<4> x total_size( { a => "foo", b => $x, c => $x } )                             
0  40253

Now we do the same, but we store references to the strings:

DB<5> x total_size( { a => "foo", b => \$x, c => \$x } )                    
0  20249

Roughly half the size!

And that is why you would use references to Perl strings. Why else would you?

About this Archive

This page is a archive of recent entries written by Jonathan Leto in June 2009.

Jonathan Leto: May 2009 is the previous archive.

Jonathan Leto: August 2009 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Clicky Web Analytics 42