<?xml version="1.0" encoding="windows-1252"?>
<node id="990845" title="Re^2: Perl 5 Optimizing Compiler, Part 5: A Vague Outline Emerges" created="2012-08-30 16:26:30" updated="2012-08-30 16:26:30">
<type id="11">
note</type>
<author id="857302">
bulk88</author>
<data>
<field name="doctext">
&lt;blockquote&gt;
Looking at the purely loop unrolling / stack side of things, I did a
rough calculation to see what improvement could be expected. I ran the
following perl code: &lt;tt class="inlinecode"&gt;&lt;font size="-1"&gt;$z = $x + $y * 3;&lt;/font&gt;&lt;/tt&gt; ($x and $y contain ints) in
a loop under cachegrind, and used the results to estimate approximately
what proportion of the execution is spent on loop/stack overhead. The
answer was approx 20%. Note that the example above was chosen specifically
to use simple perl ops where the overhead is most likely to dominate.
Perl has a lot of heavyweight ops like pp_match(), where the relative
overhead is going to be much smaller.  Also, the LLVM verison will have an
overhead of its own for setting up args and the current op, just hopefully
less than the current overhead. So that means that overall, the loop/stack
stuff is going to give us something less than 20% speedup (and probably a
lot less in practice, unless all your perl code does is lots of
lightweight stuff like additions). Set against this there &lt;i&gt;might&lt;/i&gt; be
improvements from LLVM being able to compile the resulting code better,
but my speculation is that it won't be significant.
&lt;/blockquote&gt;
You are comparing the legacy Perl 5's performance with legacy Perl 5. I dont think Will wants to just recompile Perl 5 the C program with Clang or write yet another [mod://B::C].
&lt;blockquote&gt;
&lt;p&gt;
The third thing to do with LLVM, (which is what I &lt;i&gt;think&lt;/i&gt; BrowserUK
is advocating, but I may be wrong), is the wholesale replacement of
perl's current runtime, making perl's parser convert the op tree to LLVM
IR "bytecode", and thus making a perl a first-class Perl-to-LLVM compiler,
in the same way that clang is a first-class C-to-LLVM compiler. This would
be a massive undertaking, involving understanding all the subtleties and
intricacies of 25,000 lines of pp_* functions, and writing code that will
emit equivalent IR - even assuming that you kept the rest of perl the same
(i.e. still used SVs, HVs, the context stack, pads etc).
&lt;/p&gt;
&lt;/blockquote&gt;
Why keep the pp_* and SV/contexts/pads if they aren't needed? Some CVs can be determined to be optimizable by SCA in "LLVM Perl". If a CV can't be optimized (eval string exists), the CV stays as slow "legacy" CVs. Easy things get faster, hard things stay slow. The point is to optimize "typical" Perl code, not optimize the performance of JAPHs.</field>
<field name="root_node">
990666</field>
<field name="parent_node">
990751</field>
</data>
</node>
