JIT in PHP
--
I wrote an article series about understanding how works PHP. This is the last article about this series, and in this article, we will cover JIT in PHP.
Before reading this article, I really recommend reading these articles;
1- The Magic Behind PHP
2- OPcache and Preloading in PHP
3- JIT Compiler in PHP
I cover JIT before and for this article, I just share my slide notes in addition to these articles.
Function JIT Problems
- Generally only improves the performance of CPU-bound apps
- JIT works better with strict types (use strict_types = 1)
- Function-based JIT can’t refer to objects
- JIT is useful with real hot-spots
- Don’t check whether the code is frequently used or not
- Need a smarter way (Tracing JIT)
JIT Friendly Code
- Strictly typed code and functions with scalar types can help JIT to infer types and make use of CPU registers and specialized
- use declare(strict_types=1);
How Do I Get Started
- By default, JIT is enabled, but it is turned off by limiting the buffer size.
What is JIT Flags?
- The opcache.jit directive accepts a 4-digit value to control the JIT behavior.
- In the form of CRTO, and accepts the following values for C, R, T, and O positions.
Performance with JIT
- 3x faster in PHP Benchmark Suite
- WordPress 3.5% faster
- PHP-Parser %30 faster according to Nikita Popov
Summary
- If not getting worse performance, you can turn it ON.
- Use Opcache enabled
- Use Static Analysis Tools
- Use Strict Types
- Use the smarter version (Tracing JIT)
Atakan Demircioğlu is a Full Stack Developer currently working at Jotform, a leading online form-builder platform.
He is passionate about blogging, learning, and creating. He shares his experiences on Medium and GitHub.
Twitter: https://twitter.com/atakde
Github: https://github.com/atakde