Thursday, 12 April 2007
Improving the Executor for Calling a Function in PHP |
| |
|
| |
Stas regards that calling a function in PHP is not easy. He reasons out that the executor has a lot of things to take care of while calling a function like a bunch of globals, execution state, symbol tables and the like.
He suggests the following steps to improve the executor:
- The first step, he does is to unite all execution-state related variables into single structure. This will remove reallocations and will ensure only one allocation per execution cycle and better memory usage due to the reuse of the memory blocks for frequently called functions.
- The execution data in the present form is kept in a stack. But he thinks it is unnecessary and the previous structure is enough for the data.
- But in the next point, he says that some kind of stack is necessary for function arguments and function-call-in-progress information. However, he suggests that this stack does not need to be global, as this information is not used beyond its current function call. Thus, you can make each function keep its own stack, and since you know the maximum function call depth for the code of any given user function at compile time, this stack can have fixed size too and fit into the structure.
- Once you have all call information inside the single structure, you could rewrite execute () to use loop instead of recursive call. Stas says this will allow you to reduce the stack requirements and speed up the execution loop.
- He says that various EG’s that deal with execution state would be made to work through one global ‘current execution state’ global pointing to the mega-structure.
- He suggests a new symbol table for each call, so that the symbol table allocation and the related cache stays.
- He points out that many functions are called repeatedly, but not recursively. So, he tells you that maybe you could reuse once-allocated memory block for each call of the function.
|
| |
|
Read the Post
|
| |
|
|
| |
|
|
| |
|