|
|
The just in time compiler in PyPy is a complicated piece of software. It can run some programs very fast, while others it can't yet or it'll never be able to. This is a non-exhaustive list of good and bad practices when writing code targeting PyPy, so it'll run fast.
|
|
|
|
|
|
==== General notes ====
|
|
|
=== General notes ===
|
|
|
|
|
|
Simple is better than complex. JIT is not very smart, you have to let it find out what your code does. The simpler your code is the better it'll run. Also is applies to using well-known, but unwritten coding practices. There are many optimizations that optimize common usage pattern against an uncommon usage pattern.
|
|
|
|
|
|
==== Attribute access ====
|
|
|
=== Attribute access ===
|
|
|
|
|
|
Attribute access for new style classes is ver fast if arguments are constant. For example:
|
|
|
|
... | ... | @@ -14,6 +14,20 @@ or even |
|
|
will be much faster than a dynamic version:
|
|
|
{{{setattr(x, 'a' + some_variable, 3)}}}
|
|
|
|
|
|
==== New and old style classes ====
|
|
|
=== New and old style classes ===
|
|
|
|
|
|
New style classes are faster than old style classes. Both are much faster than classes that inherit from both new and oldstyle classes. Avoid the latter at all cost. |
|
|
\ No newline at end of file |
|
|
New style classes are faster than old style classes. Both are much faster than classes that inherit from both new and oldstyle classes. Avoid the latter at all cost.
|
|
|
|
|
|
=== Calling and passing arguments ===
|
|
|
|
|
|
The simpler your calls are the better. Passing normal arguments should not pose big performance hit, while always passing a very general {{{*args}}} and {{{**kwargs}}} might. The actual depth of the call stack does not matter that much, since a lot of it might end up being inlined and generating no extra code at all.
|
|
|
|
|
|
== Things that are known to be slow, but shouldn't be ==
|
|
|
|
|
|
=== Generators ===
|
|
|
|
|
|
As of now (Feb 2011) generators are usually slower than corresponding code not using generators. Same goes for generator expressions. For most cases using list comprehension is faster.
|
|
|
|
|
|
=== String joining ===
|
|
|
|
|
|
As of now (Feb 2011) xxx |
|
|
\ No newline at end of file |