JIT?
Improve CPU cache usage
- Step 1: Decrease overall data
- Step 2: Better data locality and less indirections
- Step 3: Save the world!
- zval size reduced from 24 to 16 bytes
- Hashtable size reduced from 72 to 56 bytes
- Hashtable bucket size reduced from 72 to 32 bytes
- Immutable array optimization
<?php
$a = [];
for($i=0; $i < 100000;$i++) {
$a[] = ['abc','def','ghi','jkl','mno','pqr'];
}
echo memory_get_usage(true);
// PHP 5.x 109M
// PHP 7.0 42M no opcache
// PHP 7.0 6M with opcache enabled
- New memory allocator similar to jemalloc
- Faster hashtable iteration API
- Array duplication optimization
- PCRE JIT enabled by default
- Precomputed string hashes
- Fast ZPP (ZendParseParameters) implementation
- Faster stack-allocated zvals (instead of heap)
- Optimized VM calling
- Global register variables with gcc 4.8+
- plus hundreds of micro-optimizations
HugePage support in Opcache
./configure --enable-huge-code-pages
opcache.memory_consumption=256
opcache.huge_code_pages=1
% sysctl -w vm.nr_hugepages=256
% service php-fpm start
% cat /proc/meminfo | grep Huge
HugePages_Total: 256
HugePages_Free: 231
HugePages_Rsvd: 119
HugePages_Surp: 0
Hugepagesize: 2048 kB
JIT?