rfc:preload
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
rfc:preload [2018/10/19 08:18] dmitry |
rfc:preload [2018/11/21 22:35] cmb This RFC has already been implemented |
||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2018-10-18 | * Date: 2018-10-18 | ||
* Author: Dmitry Stogov, dmitry@zend.com | * Author: Dmitry Stogov, dmitry@zend.com | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | PHP has been using opcode caches for ages (APC, Turck MMCache, Zend Opcahce). They achieve significant performance boost by **ALMOST** completely eliminating the overhead of PHP code recompilation. With an opcode cache, files are compiled once (on the first request that uses them), and are there stored in shared memory. All the following HTTP requests use cached in shared memory | + | PHP has been using opcode caches for ages (APC, Turck MMCache, Zend OpCache). They achieve significant performance boost by **ALMOST** completely eliminating the overhead of PHP code recompilation. With an opcode cache, files are compiled once (on the first request that uses them), and are then stored in shared memory. All the following HTTP requests use the representation |
- | This proposal is about the " | + | This proposal is about the " |
- | This proposal is inspired by the "Class Data Sharing" | + | This proposal is inspired by the "Class Data Sharing" |
===== Proposal ===== | ===== Proposal ===== | ||
- | Preloading is going to be controlled by just a single new php.ini directive - **opcache.preload**. Using this directive we will specify a single PHP file - which will perform the preloading task. Once loaded, this file is then fully executed - and may preload other files, either by including them or by using the opcache_compile_file() function. Previously, I tried to implement a reach DSL to specify, which files to load, which ignore, using pattern matching etc, but then realized that writing the preloading scenarios in PHP itself was much more simple and much more flexible. | + | Preloading is going to be controlled by just a single new php.ini directive - **opcache.preload**. Using this directive we will specify a single PHP file - which will perform the preloading task. Once loaded, this file is then fully executed - and may preload other files, either by including them or by using the opcache_compile_file() function. Previously, I tried to implement a rich DSL to specify which files to load, which to ignore, using pattern matching etc, but then realized that writing the preloading scenarios in PHP itself was much more simple and much more flexible. |
For example the following script introduces a helper function, and uses it to preload the whole Zend Framework. | For example the following script introduces a helper function, and uses it to preload the whole Zend Framework. | ||
Line 50: | Line 50: | ||
</ | </ | ||
- | As mentioned above, preloaded files remain cached in opcache memory forever. Modification of their corresponding source files won' | + | As mentioned above, preloaded files remain cached in opcache memory forever. Modification of their corresponding source files won' |
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | ==== Static members and static variables ==== | ||
+ | To avoid misunderstanding, | ||
==== Preloading Limitation ==== | ==== Preloading Limitation ==== | ||
Only classes without unresolved parent, interfaces, traits and constant values may be preloaded. | Only classes without unresolved parent, interfaces, traits and constant values may be preloaded. | ||
- | Also, only top-level entities that are not nested within control structures (e.g. if()...) may be preloaded. | + | Also, only top-level entities that are not nested within control structures (e.g. if()...) may be preloaded. |
+ | |||
+ | On Windows, it's also not possible to preload classes inherited from internal ones. Windows ASLR and absence of fork() don't allow to guarantee the same addresses of internal classes in different processes. | ||
==== Implementation Details ==== | ==== Implementation Details ==== | ||
- | Preloading is implemented as a part of the opcache on top of another (already committed) patch that introduces " | + | Preloading is implemented as a part of the opcache on top of another (already committed) patch that introduces " |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 71: | Line 80: | ||
==== php.ini Defaults ==== | ==== php.ini Defaults ==== | ||
* opcache.preload - specifies a PHP script that is going to be compiled and executed at server start-up. | * opcache.preload - specifies a PHP script that is going to be compiled and executed at server start-up. | ||
- | |||
- | ===== Open Issues ===== | ||
- | * preloading in ZTS build is not supported yet | ||
===== Performance ===== | ===== Performance ===== | ||
Line 83: | Line 89: | ||
* It might be possible to pre-compile the preload script and use a binary-form (may be even native .so or .dll) to speed-up server start-up. | * It might be possible to pre-compile the preload script and use a binary-form (may be even native .so or .dll) to speed-up server start-up. | ||
* In conjunction with ext/FFI (dangerous extension), we may allow FFI functionality only in preloaded PHP files, but not in regular ones | * In conjunction with ext/FFI (dangerous extension), we may allow FFI functionality only in preloaded PHP files, but not in regular ones | ||
- | * It's possible to perform more aggressive optimizations and generate better JIT code for preloaded | + | * It's possible to perform more aggressive optimizations and generate better JIT code for preloaded |
+ | * It would be great, to extend preloading with some kind of deployment mechanism, to update preloaded bundle(s) without server restart. | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | The RFC requires 50%+1 majority | + | The RFC requires 50%+1 majority. The voting started **2018-11-06** and will close on **2018-11-14** |
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
Line 93: | Line 105: | ||
===== Implementation ===== | ===== Implementation ===== | ||
After the project is implemented, | After the project is implemented, | ||
- | - the version(s) it was merged into | + | - merged into 7.4 |
- | - a link to the git commit(s) | + | - git commit |
- a link to the PHP manual entry for the feature | - a link to the PHP manual entry for the feature | ||
- | - a link to the language specification section (if any) | ||
===== References ===== | ===== References ===== | ||
Line 105: | Line 116: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
- | |||
- | ===== Rejected Features ===== | ||
- | Keep this updated with features that were discussed on the mail lists. |
rfc/preload.txt · Last modified: 2019/01/21 18:20 by cmb