Graham and I are having a brief chat about the work he's going to do on the PECL optimizer. People have asked me to do this on-list (they may have meant the PECL list, but optimizations on PHP seem more relevant here), so here goes.
Hi Graham, So the general gist of what I have to say is that dataflow optimizations on PHP are very difficult, and nearly impossible at the function-local level. Loop-invariant hoisting and other redundant expression computation liekwise. If you're planning on working on them, we can go into more detail. I guess the biggest thing is that I'm wondering what your plans are for the PECL optimizer? I've spent about 2 years working on the phc optimizer, (and a bit longer on relevant things) so I hope that my advice will be relevant. I've taken a look through the optimizer a few times over the last while, (and even stolen some ideas from it). Here are my comments on the current code: - There is lots of code which reimplements parts of the engine, for example: ini_bool_decode, optimizer_acosh and friends, optimize_md5, optimize_crc32, optimize_sha1, optimize_class_exists and friends (to a lesser extent). There are also lots of constant foldings, like casts and "0 == false" (etc) in optimize_code_block. I don't understand why there is logic in the code for that, rather than simply executing the opcodes, or constructing an eval and executing that. - is_numeric_result: there has been great effort to figure out numeric results from pure functions, when it seems straightforward to optimizer the results straight in. Maybe that is being done elsewhere? If so, there may need to be some care taken to ensure that all optimizations terminate. - File system functions are very iffy. I would be surprised if people have content that reads from files repeatedly, but where the files do not change, and who are willing to use that flag. - Most of the identity optimizations arent safe. $x + 0 !== $x, unfortunately, due to integer coercions (parallels exist for other types/operators) - I think I saw an optimizations converting ("45" + $x) into (45+$x) - that's a great idea, which I will steal. - How does runkit (and other weird extensions) affect optimizations on constants, class_exists, etc? - The optimization "unsafe: optimize out isset()/empty() ops on GLOBALS['foo'] into $foo " is not safe, as GLOBALS['foo'] may not be the same variable as $foo ($GLOBALS may be unset, and indeed, there may be good reasons to do so). I'm also wondering what the optimizations are on fcall? I couldn't make it out. That's quite a lot, but its everything I have on the current PECL optimizer :) Thanks, Paul -- Paul Biggar paul.big...@gmail.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php