NoiseByNorthwest / php-spx

A simple & straight-to-the-point PHP profiling extension with its built-in web UI
GNU General Public License v3.0
2.14k stars 83 forks source link

opcache impact on SPX profiling? #149

Closed 8ctopus closed 4 years ago

8ctopus commented 4 years ago

Hello Sylvain,

I've tested SPX profiling of php scripts with and without opcache.

The scripts are faster when opcache is enabled, however I expected SPX not to work when the script is cached by opcache (eg. reload of the same script). I would be grateful if you could comment on how SPX and opcache interact?

NoiseByNorthwest commented 4 years ago

Hi,

SPX does work with OPcache since they do not interact between each other.

OPcache only caches the output of a PHP script compilation which is roughly an array of low level operations. It also has some extra optimization stages. But AFAIK there is no optimization which involves the replacement of a function call. Thus OPcache does not do anything during the script's execution and does not change the compiled scripts in terms of called functions.

SPX, for its part, works by intercepting function calls during the script's execution.

Furthermore SPX allows to confirm that OPcache is working as expected. To do so, profile a script with internal functions traced. Without OPcache enabled you should see a larger amount of time spent in ::zend_compile_file than with OPcache enabled and its cache warmed up.

8ctopus commented 4 years ago

Thank you for taking the time to explain it :)