[Python-Dev] Optimization idea
Thu, 19 Aug 1999 16:06:01 +0200
I just had yet another idea for optimizing Python that looks so plausible that
I guess someone else must have looked into it already (and, hence, probably
We add to the type structure a "type identifier" number, a small integer for
the common types (int=1, float=2, string=3, etc) and 0 for everything else.
When eval_code2 sees, for instance, a MULTIPLY operation it does something
like the following:
w = POP();
v = POP();
code = (BINARY_MULTIPLY << 8) |
((v->ob_type->tp_typeid) << 4) |
x = (binopfuncs[code])(v, w);
.... etc ...
The idea is that all the 256 BINARY_MULTIPLY entries would be filled with
PyNumber_Multiply, except for a few common cases. The int*int field could
point straight to int_mul(), etc.
Assuming the common cases are really more common than the uncommon cases the
fact that they jump straight out to the implementation function in stead of
mucking around in PyNumber_Multiply and PyNumber_Coerce should easily offset
the added overhead of shifts, ors and indexing.
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm