Scriptorama.nl

Header image showing a keyboard, mouse, laptop and books on design patterns

PHP internals: Compiled Variables in PHP 5

Sara Golemon, auteur van de overload en runkit extensies, heeft een interessant artikeltje geschreven over een interne wijziging van Zend Engine die gebruikt wordt voor PHP 5.1: Compiled Variables.

These !0 variables refer to a new structure in the execution stack which stores and references to the "real" variables out in userspace. The hash value for each variable is computed at compile time (meaning that it's only done once per variable no matter how often it's used and that opcode caches save this work from being done during subsequent page views at all). The first time one of these CVs is used, the engine looks it up in the active symbol table and updates the CV cache to know where it is. All subsequent uses of that compiled variable use that pre-fetched address and don't have to look it up again. On an individual lookup, this isn't a major leap forward in speed, however consider a for loop where the test value is checked on every iteration.

Deze nieuwe methode geeft in het geval van simpele variabelen mogelijk een kleine verbetering in performance. In de comments geeft Alan Knowles al aan dat deze performance gain waarschijnlijk te niet wordt gedaan door de extra compile overhead die dit veroorzaakt. Om PHP 5.1 op volle snelheid te kunnen gebruiken is het dan ook aan te raden om een bytecode cacher te installeren zoals bijvoorbeeld APC.

Doordat Sara ook duidelijk uitlegt hoe PHP 4 en 5.0 werken krijg je een aardig inzicht van hoe PHP intern met variabelen omgaat. Dus, als je ons single quotes artikel hebt gelezen en er nog niet echt chocola van kon maken moet je absoluut dit artikel even doorlezen!

Artikel: Sara Golemon: Compiled Variables

Reageer ook!

Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>