Psyco only compiles functions. It will not accelerate any code that runs outside any function, like:
class
statement. Methods themselves are accelerated just fine when you actually call them.
exec
statement or execfile or eval.
You can always work around the above limitations by creating functions and calling them instead of directly executing a time-consuming source. For example, instead of writing a short test script like
some_big_list = ... for x in some_big_list: do_something()
def process_list(lst): for x in lst: do_something() process_list(...)
As another example, a function like
def f(some_expr): for x in range(100): print eval(some_expr) # where some_expr can depend on x
def f(some_expr): my_func = eval("lambda x: " + some_expr) # -> a function object for x in range(100): print my_func(x)
In addition, inside a function, some syntactic constructs are not supported by Psyco. It does not mean that a function using them will fail; it merely means that the whole function will not be accelerated. The following table lists the unsupported constructs, along with the corresponding bytecode instruction name and number. Log files only report the bytecode instruction number, which you need to look up here.
Bytecode | Instruction name | Appears in |
---|---|---|
82 |
LOAD_LOCALS |
(1) class definitions |
84 |
IMPORT_STAR |
(5) from xx import * |
85 |
EXEC_STMT |
(2) exec xx |
86 |
YIELD_VALUE |
(3) generators |
90 |
STORE_NAME |
(5) outside functions |
91 |
DELETE_NAME |
(5) outside functions |
101 |
LOAD_NAME |
(5) outside functions |
134 |
MAKE_CLOSURE |
(4) nested scopes |
135 |
LOAD_CLOSURE |
(4) nested scopes |
136 |
LOAD_DEREF |
(4) nested scopes |
137 |
STORE_DEREF |
(4) nested scopes |
Notes:
yield
keyword) cannot be accelerated currently. If there is enough interest I can consider implementing them. This includes generator expressions (Python 2.4). Warning! The function containing a generator expression will be compiled by Psyco, but not the generator expression itself. If the latter calls other functions compiled by Psyco, then performance will be very bad: calling from Psyco to Python to Psyco comes with a significant overhead.