opcache php 原理,PHP OPcache优化级别-它们是什么?

There is an opcache.optimization_level php.ini directive. It is a bitmask a defaults to 0xffffffff - so by default OPcache does all the optimizations.

What kind of optimizations does OPcache do? What passes on bytecode are done?

Follow-up question: is there a code pattern that OPcache can optimise very well? For example, HHVM can skip execution of files that contain only class/function declarations and it just fills class/function tables.

解决方案

The bits of opcache.optimization_level correspond to:

bit 0 - pass 1:

CSE - constants subexpressions elimination

Sequences of ADD_CHAR/ADD_STRING optimization

convert CAST(IS_BOOL,x) into BOOL(x)

bit 1 - pass 2:

Convert constant operands to expected types

Convert conditional JMP with constant operands

Optimize static BRK and CONT

bit 2 - pass 3:

Convert $a = $a + expr into $a += expr

Convert $a++ into ++$a

Optimize series of JMPs

bit 3 - pass 4:

PRINT and ECHO optimization - removed

bit 4 - pass 5:

block optimization (the most expensive optimization pass which perform many different optimization patterns based on CFG - control flow graph)

bit 8 - pass 9:

register allocation (allows re-usage of temporary variables)

bit 9 - pass 10:

remove NOPs

I've looked around to see if I can find anything on any code patterns that it handles better than others, but I haven't had any luck.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值