The PHP compiler turns PHP code into “opcodes”, which are then executed on the Zend Virtual Machine. To improve performance, it is possible to optimize these opcodes prior to execution. PHP 7.1 introduces a sophisticated opcode optimization infrastructure, which uses static single assignment (SSA) form and type inference to enable more advanced optimizations.

An example: Normally, an “add $a, $b” instruction first has to check the types of $a and $b, to determine whether to perform an integer addition, or a floating point addition, or maybe even an array or GMP addition. However, if we can statically determine that $a and $b are integers, we can use a special “add_int $a, $b” instruction, which does not perform these type checks and thus improves performance. Because PHP is very dynamic, doing this is harder than it may sound…

This talk introduces the new optimization infrastructure, the optimizations based on it, and discusses which parts of the PHP language are particularly hostile to this form of optimization. This is an advanced talk, but I will try to present the topic in a way that does not require a strong compiler construction background.


Comments are closed.

Andrew Rota at 14:39 on 9 Jun 2017

Great deep-dive into the challenges (and opportunities) of opcode optimizations in PHP!

A great talk taking a peak under and seeing how opcode works and the difficulties with optimisation.

Mark Baker at 11:31 on 10 Jun 2017

Well explained step-by-step guide to what is essentially hypothesis-driven-development; looking at how opcode optimisation works; and the need to assess everything based on the edge cases (even the unlikely ones), and not simply on typical usage, to determine whether it is a viable solution; and whether the benefits justify the time and effort required to implement.
While focused on opcache optimisations, the assessment and evaluation principles used could be applied in many normal development situations as well

Jason Stanley at 12:54 on 10 Jun 2017

Very interesting look under the hood of php showing the opportunities and challenges which present themselves when attempting to improve the performance of the language.

Tim Stamp at 20:40 on 10 Jun 2017

Great overview of the optimisations that PHP does (or attempts to do) behind the scenes, and what kinds of avenues the devs behind the PHP language are exploring to improve the performance of PHP even further.

Peter Fisher at 23:05 on 10 Jun 2017

A well explained insight into the challenges of Opcode PHP optimisation.

Nils Adermann at 16:06 on 11 Jun 2017

Really enjoyed the examples of things that make seemingly simple optimizations close to impossible, which really helps understand why they aren't (yet) being done.

James Titcumb at 09:28 on 12 Jun 2017

Great technical exploration, really well explained.

A great talk. It's really interesting to learn a bit more about what goes on under the hood and the kinds of testing and research that goes on.

Every conference should have some kind of internals talk.

Mark Dain at 21:09 on 12 Jun 2017

Fantastic talk that gave a really good insight into the struggles of the PHP devs to optimize a complex language. I thought the pacing was good and the content was great. 5/5

Neil Nand at 22:52 on 15 Jun 2017

Really good talk on some of the optimisations of PHP internals but I went in with the impression that there'd be more information on how PHP developers could optimise the code the write. Maybe just make it a little clearer on the talk description?