[pypy-dev] Jit hints from python

Timothy Baldridge tbaldridge at gmail.com
Wed May 23 14:44:07 CEST 2012


While looking at ways to optimize the Clojure-Py code
(http://github.com/halgari/clojure-py) for pypy, I'm noticing that
much of Clojure-Py could benefit greatly from giving purefunction
hints to the JIT. For example, let's look at the polymorphic Clojure
functions known as "protocols":


def ProtocolFn(object):
    def __init__(self):
        self.d = {}

    def extend(self, tp, fn):
        self.d[tp] = fn

    def getFn(self, tp):
        return self.d[tp]

    def __call__(self, *args, **kw):
        return self.getFn(type(args[0]))(*args **kw)


Now, if I was writing this in RPython I would have extend clone the
dictionary each time, then makr getFn as "pure" and suddenly I'd
expect to see the JIT start in-lining calls to this ProtocolFn, and I
would also expect to see a rather major performance boost. Also, since
the majority of Clojure code deals with immutable data structures, I
could actually mark 80% of my data structure functions as pure.

So my question is, how easy/hard would it be to somehow get a
@purefunction decorator in Python instead of just RPython? For that
matter, having __immutable_fields__ would also be nice, but that may
be asking for too much.

Timothy

-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)


More information about the pypy-dev mailing list