Why Perl needs a VM

ben@bpfh.net ben at bpfh.net
Tue Sep 4 19:20:31 BST 2007


On Wed, Sep 05, 2007 at 12:04:55AM +0930, Toby Corkindale wrote:
>ben at bpfh.net wrote:
>> I've got to thinking recently about the issue of whether 
>> Perl (and dynamic languages in general) need VMs.
>> 
>> I'd been increasingly coming to the conclusion that they do, and
>> then someone in my team performed a piece of performance analysis
>> which really made me think.
>> 
>> Our application is a large (currently all-Perl) mail sending pipeline.
>> 
>> Having profiled it, we know that in the critical sending section, the
>> application is spending most of its time either doing regex or scanning
>> XML using XPaths.
>> 
>> The former task has Perl showing a minor, but significant performance 
>> advantage over Java, presumably because so much of the real work is taking
>> place in optimised C code, down below the runops dispatch.
>> 
>> The latter task is performed in pure Perl, and here Java out-performs by
>> a large factor (I've heard 20-100x, but I need to dig into those numbers
>> more - I don't think I want to take them on face value).
>
>You mention below that you are thinking of re-writing parts of the app
>in Java, because of the slow Pure-Perl performance.. can you instead
>just swap to using a Perl module that evaluates the XPaths via a C
>implementation, thus gaining the speed advantage over Java again, as
>with the regexes?
>(I think XML::LibXML::XPathContext is an example of such?)

I've had a poke at the code and sure enough, we're using XPathContext, which 
I'd thought was a pure perl piece on top of XML::LibXML. It isn't - it's got
a C implementation at its heart.

The Java implementation is still substantially quicker. I want to drill in
on the numbers, and the Java libs are probably proprietary, so I may not be 
able to post any numbers, but I am now pretty convinced that the "Java, therefore
slow" mantra really isn't true any more, at least in this application.

I'll report back anything I find which I can post. I might also have a go at
reproducing some of these tests at home with standard Java XML libs.

Ben


More information about the london.pm mailing list