Hi, I spoke with some devs yesterday about spl_object_hash performance and alternatives to solve it. Seems that md5 applied inside it is the responsable for that.
After some tips from Lars, we came with a patch (at the bottom of this email). The new proposed function is already being used in Doctrine 2.0 (to be released in 2009), which takes advantages of new features of 5.3. During our tests, everything passed without conflicting or leading to unpredictable values. The performance did not increase too much as I expected, but it reached to a good value for me now. It's as fast as calculating the spl_object_hash once and do a method call, which is an interesting value. It seems that Marcus controls the commit access to SPL. So I'm turning the conversation async, since I cannot find him online at IRC. So, can anyone review the patch, comment it and commit if approved? Thanks in advance, Index: ext/spl/php_spl.c =================================================================== RCS file: /repository/php-src/ext/spl/php_spl.c,v retrieving revision 1.52.2.28.2.17.2.33 diff -u -r1.52.2.28.2.17.2.33 php_spl.c --- ext/spl/php_spl.c 30 Nov 2008 00:23:06 -0000 1.52.2.28.2.17.2.33 +++ ext/spl/php_spl.c 16 Dec 2008 19:05:05 -0000 @@ -682,6 +682,23 @@ } /* }}} */ +/* {{{ proto string spl_object_id(object obc) + Return id for the given object */ +PHP_FUNCTION(spl_object_id) +{ + zval *obj; + char *string; + int len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { + return; + } + + len = spprintf(&string, 0, "%p%d", Z_OBJ_HT_P(obj), Z_OBJ_HANDLE_P(obj)); + RETURN_STRING(string, 1); +} +/* }}} */ + PHPAPI void php_spl_object_hash(zval *obj, char *md5str TSRMLS_DC) /* {{{*/ { int len; @@ -798,6 +815,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_object_hash, 0, 0, 1) ZEND_ARG_INFO(0, obj) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_object_id, 0, 0, 1) + ZEND_ARG_INFO(0, obj) +ZEND_END_ARG_INFO() /* }}} */ /* {{{ spl_functions @@ -813,6 +834,7 @@ PHP_FE(class_parents, arginfo_class_parents) PHP_FE(class_implements, arginfo_class_implements) PHP_FE(spl_object_hash, arginfo_spl_object_hash) + PHP_FE(spl_object_id, arginfo_spl_object_id) #ifdef SPL_ITERATORS_H PHP_FE(iterator_to_array, arginfo_iterator_to_array) PHP_FE(iterator_count, arginfo_iterator) -- Guilherme Blanco - Web Developer CBC - Certified Bindows Consultant Cell Phone: +55 (16) 9215-8480 MSN: guilhermebla...@hotmail.com URL: http://blog.bisna.com São Paulo - SP/Brazil