͞Βʹ͘ͳΔPHPnunulk PHPΧϯϑΝϨϯεԭೄ
View Slide
ຊ͓͢Δ͜ͱ• ࣗݾհ• PHP 7.4 Ͱಋೖ͞ΕΔ Opcache Preloading ͱ FFI• ʢ͓·͚ʣNim ͷհ
ࣗݾհ• ໊લ: nunulkʢ͵͵Δ͘ʣ• ৬ۀ: ϑϦʔϥϯεͷΣϒΤϯδχΞ• ਆಸݝ͔Βདྷ·ͨ͠• PHPͷ͖ͳͱ͜Ζ: ՄมؔɺϚδοΫϝιου• Laravel Meetup Okinawa ࢀՃ: 45%
I work for
PHP 7.4 is coming on Nov. 28th, 2019 !RC3 is now available.
New features• Typed Properties• Arrow Functions• Null coalescing assignment operator• Spread operator in arrays• Covariant Returns and Contravariant Parameters• Opcache Preloading• FFI
Opcache Preloading• αʔόىಈ࣌ʹ Opcache ΛϝϞϦ্ʹϩʔυ͓ͯ͘͠Έ• ॳճΞΫηε࣌ʹΩϟογϡ͕ޮ͘Α͏ʹͳΔ• ͨͩ͠ࢦఆͰ͖Δͷ1ϑΝΠϧͷΈ
Opcache Preloading// ϑϨʔϜϫʔΫͷͯ͢ͷϑΝΠϧΛΩϟογϡ͢Δ$frameworkDir = $baseDir . 'vendor/laravel/framework/src/Illuminate';$paths = load_all_files([$frameworkDir]);foreach ($paths as $path) {opcache_compile_file($path); }
Opcache Preloadingab -n 100 -c 10 http://localhostOpcache ͳ͠Requests per second: 0.91 [#/sec] (mean)Time per request: 11010.544 [ms] (mean)Opcache ͋ΓRequests per second: 5.34 [#/sec] (mean)Time per request: 1872.084 [ms] (mean)Opcache ͋Γ w/ preloadRequests per second: 6.32 [#/sec] (mean)Time per request: 1582.046 [ms] (mean)
Opcache Preloading• Opcache.enable = 1 ͢Δ͚ͩͰे͘ͳΔ• αʔόΛ࠶ىಈ͠ͳ͍ͱΩϟογϡߋ৽͞Εͳ͍ͷͰɺӡ༻ͷࡍҙ͕ඞཁ• Composer Ͱಋೖ͕ݕ౼͞Ε͍ͯΔͷͰɺকདྷతʹpreload͢ΔରͷબఆΛ composer ͔Βߦ͑ΔΑ͏ʹͳΔ͔͠Εͳ͍
FFI - Foreign Function Interface• PHP ͔ΒωΠςΟϒϥΠϒϥϦʢ.so, .dylib, .dllʣΛݺͿΈ• Python, Ruby, Java ͳͲͰ͢Ͱʹ࠾༻͞Ε͍ͯΔ
PHP ͔ΒωΠςΟϒϥΠϒϥϦΛݺͿΈ• PHP extension• Zend extension
FFI$libfib = FFI::cdef('int fib(int a);', ‘../nim/libfib.so');$ret = $libfib->fib(40);var_dump($ret);// int(102334155)
FFI// for/if Λͬͯ N ·ͰͷۮͷΛܭࢉ͢Δ # php index.php loop --php 10000000.056366920471191 # php index.php loop --ffi 10000000.037209987640381 // N ൪ͷϑΟϘφονΛ࠶ؼͰܭࢉ͢Δ# php index.php fib --php 404.6368939876556# php index.php fib --ffi 400.28206396102905// MySQL ʹ N ݅σʔλΛૠೖ͢Δ# php index.php mysql --php 10000.47904992103577# php index.php mysql --ffi 10000.57981204986572
FFI - Foreign Function Interface• ͍ॴΛݟۃΊΔͷ͕͍͕͠ɺہॴతʹεϐʔυΞοϓͤ͞Δબࢶͷͻͱͭ• େྔͷܭࢉΛͤ͞Δͷʹ͍͍ͯΔ• ͢ͰʹΤΫεςϯγϣϯ͕͋ΔͷͰ͋ΕͦͪΒΛ͏΄͏͕͍
ʢ͓·͚ʣNim ͷհ
Nim• γεςϜϓϩάϥϛϯά͚੩తܕ͚ݴޠ• ϚϧνύϥμΠϜ• Python ʹࣅͨߏจΛ࣋ͭ• C/C++/JavaScript ʹτϥϯεύΠϧ͢Δ͜ͱ͕Ͱ͖Δ• 20199݄ʹ 1.0 ͕ϦϦʔε͞Ε͔ͨΓ
Nimproc fib(a: cint): cint {.exportc, cdecl, dynlib.} =if a <= 2:result = 1else:result = fib(a - 1) + fib(a - 2)
Nim$ nim c -d:release --noMain --header --app:lib fib.nim $ ls libfib.solibfib.so
Nim$libfib = FFI::cdef('int fib(int a);', ‘../nim/libfib.so');$ret = $libfib->fib(40);var_dump($ret);
ڵຯͷ͋Δํ Nim + FFI Ͱ ॏ͍ॲཧͷߴԽʹ νϟϨϯδͯ͠Έ͍ͯͩ͘͞
JIT in PHP 8.0 is comingon Sep. 23, 2021 !
͞Βʹ͘ͳΔ PHP ࠓޙͱΑΖ͓͘͠ئ͍͠·͢