블로그

php8 , JIT(Just-In-Time) 성능 측정

Code › PHP · 2022-02-18 · 공개

* opcache와 jit 차이
OpCache (php5.5): 인터프리터가 생성한 OPCode를 메모리에 저장하여 실행

    - 저장한 OPCode를 실행할때도 VM을 거처서 CPU에서 실행됨

 

JIT (php8.0) : JIT(Just-In-Time) 컴파일러가 생성한 기계어를 메모리 저장하여 실행

    - 저장한 기계어 코드는 CPU에서 바로 실행됨

 

https://php.watch/versions/8.0/JIT

//-------------------------------------
php.ini 파일 설정
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=256M
opcache.jit=tracing

//-------------------------------------
opcode.jit 옵션
    disable : 완전 불가
    off : 불가, 런타임에서 동작시키기 가능
    on : tracing과 동일
    tracing :  1254 (CRTO)
    function :  1205 (CRTO)
    4자리숫자 : CRTO

C: CPU-specific Optimization Flags
    0: Disable CPU-specific optimization.
    1: Enable use of AVX, if the CPU supports it.

R: Register Allocation
    0: Don't perform register allocation.
    1: Perform block-local register allocation.
    2: Perform global register allocation.

T: Trigger
    0: Compile all functions on script load.
    1: Compile all functions on first execution.
    2: Profile first request and compile the hottest functions afterwards.
    3: Profile on the fly and compile hot functions.
    4: Currently unused.
    5: Use tracing JIT. Profile on the fly and compile traces for hot code segments.

O: Optimization Level
    0: No JIT.
    1: Minimal JIT (call standard VM handlers).
    2: Inline VM handlers.
    3: Use type inference.
    4: Use call graph.
    5: Optimize whole script.

//-------------------------------------

opcache.jit 옵션 값에 따른 성능 측정 결과

    - tracing은 20-30%, function은 10-15% 성능 향상

 

    - 초당 실행수

 
코드1
코드2
코드3
opcache_get_status()['jit']
결과값 kind, opt_level, opt_flags

disable
2439
2030
343
000

off
2439
2040
351
000

on
2962
2631
462
546

tracing(1254)
2857
2285
441
546

1254
2985
2631
466
546

function(1205)
2666
2352
401
056

1205
2941
2597
458
056

1255
2962
2614
475
556

 

//-----------------------------------------------------------------------------

 

The Definitive PHP 7.2, 7.3, 7.4, 8.0, and 8.1 Benchmarks (2022) 
https://kinsta.com/blog/php-benchmarks/

PHP 8.1 Performance Is Continuing To Improve With Early Benchmarks
https://www.phoronix.com/scan.php?page=news_item&px=PHP-8.1-Benchmarks-Perf-Early

PHP 8: JIT performance in real-life web applications
https://stitcher.io/blog/jit-in-real-life-web-applications

Just-In-Time (JIT) Compilation in PHP 8.0
https://lindevs.com/just-in-time-jit-compilation-in-php-8-0/

 

//-------------------------------------

https://www.php.net/releases/8.0/en.php

//-------------------------------------

 

벤치마크 소스
https://github.com/php/php-src/blob/master/Zend/bench.php

https://stitcher.io/blog/preloading-in-php-74
https://www.cloudpanel.io/docs/v1/guides/php/opcache-preload

알림