zendtech / ZendOptimizerPlus

Other
915 stars 142 forks source link

Unnecessary alllocation of arBuckets space in SMA #103

Closed TerryE closed 11 years ago

TerryE commented 11 years ago

zend_accelerator_util_funcs.c lines 79 and 84 initialise the hash tables for the persistent script function and class tables to 128 and 16 size_t slots for the arBuckets vector. What is the rationale here? These tables are allocated in emalloc space and grown to complete size there before being copied to SMA in zend_persist.c. This copy is based on the nTableSize not the nNumOfElements, so in the case of the function table 1K will be allocated (on 64bit builds) even though only a few top level functions are defined.

OK, the 128/16 sizing potentially saves few HashTable resizes during initial compilation (once-per-compile) (a few μS) but at a cost of 1K/128 bytes space in per script/function loaded into SMA at runtime. OK this is relative small beer, but it is unnecessary wasted space nonetheless.

Why not just use the default 8 and save the space in the SMA?

dstogov commented 11 years ago

Good catch. I think it makes sense to compact the hash tables before storing them in shared memory. (using zend_hash_rehash).

dstogov commented 11 years ago

Done. (see compact_persistent_script() in zend_accelerator_util_funcs.c)