[Python-Dev] optimizing simple function calls [was PEP 275 (switching)]
Neil Schemenauer
nas@python.ca
Mon, 12 Nov 2001 07:23:05 -0800
M.-A. Lemburg wrote:
> The current solution to this problem lies in using a dispatch
> table to find the case implementing method to execute depending on
> the value of the switch variable (this can be tuned to have a
> complexity of O(1) on average, e.g. by using perfect hash
> tables). This works well for state machines which require complex
> and lengthy processing in the different case methods. It does not
> perform well for ones which only process one or two instructions
> per case, e.g.
>
> def handle_data(self, data):
> self.stack.append(data)
It would be nice if we could make simple methods like this faster.
Maybe something like a special fast path for methods with no blocks and
no variable or keyword arguments. I think optimizing small functions
would be a greater overall benefit to the average Python program.
Neil