pmmp / ext-pmmpthread

Fork of https://github.com/krakjoe/pthreads with a revamped API and PHP 8.1+ support
Other
81 stars 17 forks source link

Store zval directly for simple types in pthreads_store #43

Closed dktapps closed 3 years ago

dktapps commented 3 years ago

pthreads_store currently malloc()s a new pthreads_storage for every item, regardless of type. This is wasteful because the underlying HashTable which pthreads uses for shared properties uses Z_PTR to wrap around these storages.

Thus, the access for an integer becomes

(Z_PTR_P(zend_hash_find(propName)))->lval

when instead, it could take one less allocation and also one less indirection by storing a ZVAL_LONG in the HashTable directly, instead of a ZVAL_PTR->pthreads_storage.

This would both improve performance (slightly) and reduce memory usage of Threaded objects.