Skip to content

Commit e622e86

Browse files
committed
Reduce memory usage of SplObjectStorage
Track an 8-byte pointer as the key instead of 16-byte zval. (4 byte on 32-bit builds) The memory used for a set of 1 million objects decreased from 114 MiB to 106 MiB. Use the new `Z_PARAM_*` APIs to parse the `zend_object*` pointer directly Closes GH-6566
1 parent ce2e107 commit e622e86

File tree

3 files changed

+82
-72
lines changed

3 files changed

+82
-72
lines changed

ext/spl/php_spl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,11 @@ PHP_FUNCTION(spl_autoload_functions)
628628
/* {{{ Return hash id for given object */
629629
PHP_FUNCTION(spl_object_hash)
630630
{
631-
zval *obj;
631+
zend_object *obj;
632632

633-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &obj) == FAILURE) {
634-
RETURN_THROWS();
635-
}
633+
ZEND_PARSE_PARAMETERS_START(1, 1)
634+
Z_PARAM_OBJ(obj)
635+
ZEND_PARSE_PARAMETERS_END();
636636

637637
RETURN_NEW_STR(php_spl_object_hash(obj));
638638
}
@@ -651,7 +651,7 @@ PHP_FUNCTION(spl_object_id)
651651
}
652652
/* }}} */
653653

654-
PHPAPI zend_string *php_spl_object_hash(zval *obj) /* {{{*/
654+
PHPAPI zend_string *php_spl_object_hash(zend_object *obj) /* {{{*/
655655
{
656656
intptr_t hash_handle, hash_handlers;
657657

@@ -661,7 +661,7 @@ PHPAPI zend_string *php_spl_object_hash(zval *obj) /* {{{*/
661661
SPL_G(hash_mask_init) = 1;
662662
}
663663

664-
hash_handle = SPL_G(hash_mask_handle)^(intptr_t)Z_OBJ_HANDLE_P(obj);
664+
hash_handle = SPL_G(hash_mask_handle)^(intptr_t)obj->handle;
665665
hash_handlers = SPL_G(hash_mask_handlers);
666666

667667
return strpprintf(32, "%016zx%016zx", hash_handle, hash_handlers);

ext/spl/php_spl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ ZEND_END_MODULE_GLOBALS(spl)
6262
ZEND_EXTERN_MODULE_GLOBALS(spl)
6363
#define SPL_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(spl, v)
6464

65-
PHPAPI zend_string *php_spl_object_hash(zval *obj);
65+
PHPAPI zend_string *php_spl_object_hash(zend_object *obj);
6666

6767
#endif /* PHP_SPL_H */

0 commit comments

Comments
 (0)