pointless musings on performance

Tim Wintle tim.wintle at teamrubber.com
Tue Nov 24 14:16:18 EST 2009


On Tue, 2009-11-24 at 18:25 +0000, Antoine Pitrou wrote:
> Le Tue, 24 Nov 2009 08:58:40 -0800, Paul Boddie a écrit :
> > As you
> > point out, a lot of this RISC vs. CISC analysis (and inferences
> drawn
> > from Python bytecode analysis) is somewhat academic: the cost of the
> > JUMP_IF_FALSE instruction is likely to be minimal in the context of
> all the activity going on to evaluate the bytecodes.
> 
> Sorry, I have trouble parsing your sentence. Do you mean bytecode 
> interpretation overhead is minimal compared to the cost of actual
> useful work, or the contrary?
> (IMO both are wrong by the way)

Out of interest - has anyone else spotted that the call to
PyObject_IsTrue in the XXX_JUMP_IF_YYYY blocks performs two unnecessary
pointer comparisons?

==== ceval.c ====
if (w == Py_True) {
    Py_DECREF(w);
    FAST_DISPATCH();
}
if (w == Py_False) {
    Py_DECREF(w);
    JUMPTO(oparg);
    FAST_DISPATCH();
}
err = PyObject_IsTrue(w);
Py_DECREF(w);
.
.
.
==================

==== object.c ====
PyObject_IsTrue(PyObject *v)
{
        Py_ssize_t res;
        if (v == Py_True)
                return 1;
        if (v == Py_False)
                return 0;
.
.
.
==================

Would it be worth in-lining the remaining part of PyObject_IsTrue in
ceval?

> Another data point I've heard is that people who have tried a very
> crude form of Python-to-C compilation (generating the exact C code
> corresponding to a function or method, using Python's C API and
> preserving dynamicity without attempting to be clever) have apparently
> reached speedups of up to 50% (in other words, "twice as fast").

That's roughly what I get with Cython - which does exactly that.

Tim




More information about the Python-list mailing list