Re: Optimizing add_assoc_* with static keys (WAS: Re: [PHP-DEV] [PATCH] array_combine is not binary-key safe)

From: Date: Sun, 23 Jul 2006 09:23:24 +0000
Subject: Re: Optimizing add_assoc_* with static keys (WAS: Re: [PHP-DEV] [PATCH] array_combine is not binary-key safe)
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-24897@lists.php.net to get a copy of this message
Hi Richard, Andrei, Hold on about a patch to optimize add_assoc_* and hard-coded keys. I just finished some testing to see what difference it makes: none! :-) Compilers must optimize strlen("static string") to the literal value; at least VC++ Express does. Using a dynamic string from estrdup(), *_ex with the hard-coded length was about 10% faster with a 12 character key on my old system (dual 930MHz). But again, no difference with static ones like in PHP's code. It was an optimization though in array_combine(), being dynamic key values. So, nothin' to worry about here... :-) Matt ----- Original Message ----- From: "Matt W" Sent: Saturday, July 22, 2006 > Hi Richard, > > Replacement script made it pretty simple I guess. :-) But sizeof("key")+1 > should just be sizeof("key") (which == strlen("key")+1). > > Are there any uses of add_u_assoc_* with hard-coded keys? > > These changes make things look a little messy, you think? The string is in > 2 places, etc... (Maybe why it wasn't done in the first place?) Seems like > that ZEND_STRS() macro you mentioned would work well. Or maybe cleanest > would be some new add_static_assoc_* macros (and _u versions if needed), or > some other naming convention, that uses sizeof() instead of strlen()+1. > > What do the main devs think? > > > Matt

« previous php.internals (#24897) next »