Friday, 16 March 2007
Would PHP Benefit from JIT compilation? |
| |
|
| |
Jacob Santos in a post over his blog weighs the pros and cons of JIT compilation in PHP. He asks JIT compilation is present in Java, Python and .NET so why not in PHP. He talks about PHP Internals that Gopal is working on JIT implementation for PHP. He also mentions about libjit alpha. He predicts that it will be a helpful solution in the future.
He has put a list of questions and problems to give an overview to know if PHP will benefit from JIT Compilation.
He asks about the advantage over opcode caching. He answers that it would be quicker, since JIT would be compiling the PHP opcodes to machine code, PHP wouldn’t need to interpret the opcodes to get it running.
He also asks which JIT library is the best one. He says, he has been looking into various JIT libraries. A lot of good ones did come up as well as one’s that would be excellent in a few years. Many different PHP JIT implementations could be made from all of them, which could also help decide which one is better, he says.
He thinks if writing PHP extensions negate the need for JIT compilation. He says if he needs to write an extension, he should write the entire thing in C as it would be faster than having any code in PHP. The desire of PHP is its ease of development and the applications and libraries that are developed with it. If it is possible to bring PHP userland code to the level of speed as the PHP extensions then it is worth exploring, he explains.
He lists two problems, which are as follows:
Problem 1: A JIT library that works with PHP would have to support all of the architectures that PHP can run on
He says it is true that, if only CPU x86 and x86-64 are supported then it wouldn’t work with most Macintosh users and most IBM mainframe. But there is other architecture that aren’t x86 compatible for servers and mainframes that would run PHP and host PHP web sites. At the very least, the JIT compiler would have to have a fall back for architectures that it doesn’t support and add those in later. In that case, he says if you do have supported architecture, you would see an increase, but if not then you’ll have the opcode cache to fall back on.
Problem 2: A JIT compiler is not going to achieve anything without either storing the results or caching them
He says that the JIT compilation would have to stay in memory or stored in a file to achieve any benefit. The JIT compilation does take a little bit of time to convert the opcodes to machine code before running. It doesn’t have to be the whole script; it can be a function or a class, or a small section of PHP code. The delay, if it had to do so for each default compilation of PHP source code would negate the benefits of the JIT compiler.
That said, the JIT compiler would either have to work on top of the opcode cache, with the opcode cache, or instead of the opcode cache. The opcode feature will become part of the JIT compiler, he explains.
|
| |
|
Read the Post
|
| |
|
|
| |
|
|
| |
|