[pypy-dev] JIT'ed function performance degrades

Maciej Fijalkowski fijall at gmail.com
Thu Aug 19 12:11:29 CEST 2010


Hi

On Thu, Aug 19, 2010 at 8:48 AM, Paolo Giarrusso <p.giarrusso at gmail.com> wrote:
> On Thu, Aug 19, 2010 at 03:25, Hart's Antler <bhartsho at yahoo.com> wrote:
>> I am starting to learn how to use the JIT, and i'm confused why my function gets slower over time, twice as slow after running for a few minutes.  Using a virtualizable did speed up my code, but it still has the degrading performance problem.  I have yesterdays SVN and using 64bit with boehm.  I understand boehm is slower, but overall my JIT'ed function is many times slower than un-jitted, is this expected behavior from boehm?
>>
>> code is here:
>> http://pastebin.com/9VGJHpNa
>
> I think this has nothing to do with Boehm.

I don't think as well

<snip>

> Moreover, I'm not sure you need to use the JIT yourself.
> - Your code is RPython, so you could as well just translate it without
> JIT annotations, and it will be compiled to C code.
> - Otherwise, you could write that as a app-level function, i.e. in
> normal Python, and pass it to a translated PyPy-JIT interpreter. Did
> you try and benchmark the code?
> Can I ask you why you did not write that as a app-level function, i.e.
> as normal Python code, to use PyPy's JIT directly, without needing
> detailed understanding of the JIT?
> It would be interesting to see a comparison (and have it on the web,
> after some code review).

JIT can essentially speed up based on constant folding based on
bytecode. Bytecode should be the only green variable here and all
others (that you don't want to specialize over) should be red and not
promoted. In your case it's very likely you compile new loop very
often (overspecialization).

>
> Especially, I'm not sure that as currently written you're getting any
> speedup, and I seriously wonder whether the JIT could give an
> additional speedup over RPython here (the regexp interpreter is a
> completely different case, since it compiles a regexp, but why do you
> compile an array?).

That's silly, our python interpreter is an RPython program. Anything
that can have a meaningfully defined "bytecode" or a "compile time
constant" can be sped up by the JIT. For example a templating
language.

> I think just raw CPython can be 340x slower than C (I assume NumPy
> uses C)

You should check more and have less assumptions.

>
> So, every time you change the value of a green variable, the JIT will
> have to recompile again the function. Note that actually, I think, for
> each new value of the variable, first a given number of iterations
> have to occur (1000? 10 000? I'm not sure), then the JIT will spend
> time creating a trace and compiling it. The length of the involved
> arrays is maybe around the threshold, maybe smaller, so you get "all
> pain, and no gain".
>

to be precise for each combination of green variables there has to be
a 1000 (by default) iterations. If there is no such thing, you'll
never compile code and simply spend time bookkeeping.

Cheers,
fijal



More information about the Pypy-dev mailing list