Skip to content

Commit

Permalink
Optimized access to temporary and compiled VM variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Dec 4, 2012
1 parent 7848502 commit 7651d64
Show file tree
Hide file tree
Showing 12 changed files with 1,429 additions and 1,467 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ PHP NEWS
?? ??? 201?, PHP 5.5.0

- General improvements:
. Optimized access to temporary and compiled VM variables. 8% less memory
reads. (Dmitry)
. The VM stacks for passing function arguments and syntaticaly nested calls
were merged into a single stack. The stack size needed for op_array
execution is calculated at compile time and preallocated at once. As result
Expand Down
11 changes: 11 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ PHP 5.5 UPGRADE NOTES
corresponding stack space is preallocated together with execute_data.
ZEND_SEND* and ZEND_DO_FCALL* don't need to check for stack overflow
anymore.
- Removed execute_data->Ts field. The VM temporary variables always allocated
immediately before execute_data structure. Now they are accessed by offset
from the execute_data base pointer (instead of execute_data->Ts). Compiler
stores new offsets in op_array->opcodes[*].op?.num. You can use macros
EX_TMP_VAR() and EX_TMP_VAR_NUM() to access temp_variable by offset or
number. You can convert number to offset using EX_TMP_VAR_NUM(0, num) or
offset to number (EX_TMP_VAR(0,offset)-EX_TMP_VAR_NUM(0,0)).
- Removed execute_data->CVs field. The VM compiled variables always allocated
immediately after execute_data structure. Now they are accessed by offset
from the execute_data base pointer (instead of execute_data->CVs). You can
use macros EX_CV_NUM() to access compiled variables by number.

========================================
2. New Features
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ ZEND_API zend_bool zend_is_compiling(TSRMLS_D) /* {{{ */

static zend_uint get_temporary_variable(zend_op_array *op_array) /* {{{ */
{
return (op_array->T)++ * ZEND_MM_ALIGNED_SIZE(sizeof(temp_variable));
return EX_TMP_VAR_NUM(0, (op_array->T)++);
}
/* }}} */

Expand Down
7 changes: 5 additions & 2 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ struct _zend_execute_data {
zend_function_state function_state;
zend_op_array *op_array;
zval *object;
union _temp_variable *Ts;
zval ***CVs;
HashTable *symbol_table;
struct _zend_execute_data *prev_execute_data;
zval *old_error_reporting;
Expand All @@ -404,6 +402,11 @@ struct _zend_execute_data {

#define EX(element) execute_data.element

#define EX_TMP_VAR(ex, n) ((temp_variable*)(((char*)(ex)) + ((int)(n))))
#define EX_TMP_VAR_NUM(ex, n) (EX_TMP_VAR(ex, 0) - (1 + (n)))

#define EX_CV_NUM(ex, n) (((zval***)(((char*)(ex))+ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data))))+(n))


#define IS_CONST (1<<0)
#define IS_TMP_VAR (1<<1)
Expand Down
Loading

0 comments on commit 7651d64

Please sign in to comment.