# [PATCH] Reduce heap memory consumption

- Thread: https://externals.io/message/49610
- Original archive: https://news-web.php.net/php.internals/49610
- Started by Dmitry Stogov on 2010-09-13T11:58:53+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #49610 — Dmitry Stogov — 2010-09-13T11:58:53+00:00

URL: https://externals.io/message/49610#49610

Hi,

The attached patch modifies internal ZE data structures.
It gives 4% less heap memory usage on waiting PHP process (2210KB 
instead of 2304KB) and up to 7% improvement on applications with many 
classes (ZendFramework benchmark uses 17.7M instead of 19M). It also 
makes small speedup on some big applications with opcode caches, because 
of less memory transfer.

The patch performs the following optimizations:

1) zend_function.pass_rest_by_reference is replaced by 
ZEND_ACC_PASS_REST_BY_REFERENCE in zend_function.fn_flags

2) zend_function.return_reference is replaced by 
ZEND_ACC_RETURN_REFERENCE in zend_function.fn_flags

3) zend_arg_info.required_num_args removed. it was needed only for 
internal functions. Now the first arg_info for internal function (which 
has special meaning) is represented by zend_internal_function_info 
structure.

4) zend_op_array.size, size_var, size_literal, current_brk_cont, 
backpatch_count moved into CG(context), because they are used only 
during compilation.

5) zend_op_array.start_op is moved into EG(start_op), because it's used
only for 'interactive' execution of single top-level op-array.

6) zend_op_array.done_pass_two is replaced by ZEND_ACC_DONE_PASS_TWO in 
zend_op_array.fn_flags.

7) the sise of op_array.vars is reduced during pass_two.

8) zend_class_entry.constants_updated is replaced by 
ZEND_ACC_CONSTANTS_UPDATED in zend_class_entry.ce_flags

9) The size of zend_class_entry is reduced by sharing the same memory 
space by different information for internal and user classes. See 
zend_class_inttry.info union.

Of course the patch will affect some extensions (e.g. APC and xdebug), 
but it shouldn't be difficult to fix them.

I'm going to commit the patch by the end of this week in case of no 
objections. I'll also add corresponding notes into UPGRADING.INTERNALS.

Thanks. Dmitry.
