-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] opcache.allow_cache=0: Opcode optimization without caching #5504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I like the idea of having optimization without caching, but the way to go about this is definitely moving the optimizer into Zend and making it available completely independently of the opcache extension. This has been "planned" for a long time, but never actually happened. |
I'd agree that it would be more reasonable to have the optimizer bundled with php, especially since I'm not aware of competing optimizers for php 7/8. I'm also concerned about it staying "planned", since
Also, what is the plan for this?
What would happen to current ini flags? It would be useful to continue supporting So if we kept that prefix for other optimization/caching settings when moving the optimizer into Zend, I'd assume that this might end up with the name
|
Aside, unrelated to this proposal: If opcache.file_cache_only was available, I wonder if
|
d7ce79f
to
efeaf13
Compare
Currently, it isn't possible to enable optimizations without enabling caching. They should be orthogonal features - it's already possible to cache without optimization passes (`opcache.optimization_level=0`) (In use cases such as running a web server in apache, it's very desirable to both cache and optimize opcodes. For short-lived cli scripts, either file_cache or disabling opcache (to reduce optimization overhead) is often useful. In a few use cases, it's desirable to optimize without any caching) Being forced to either enable shared memory caching or file_cache_only causes these problems: - **For file_cache_only, users would be forced to manage the file cache.** - Users may not be confident in properly handling all potential edge cases. - End users of applications may not be familiar with opcache. (Concerns include running out of disk space, needing to clear stale entries, concerns about opcode corruption or opcodes for the wrong file contents not being fixed after restarting a process, etc) - **The shared memory block uses up a lot of RAM when individual PHP processes are known to be long-lived and don't have a common memory address space.** (e.g. multiple long-lived php scripts managed by something that is not a php script (e.g. `supervisord`, daemons, tools run in the background in IDEs, etc)) The opcodes are duplicated in shmem, which wastes memory in use cases where opcodes are stored in the cache but never retrieved. The default for opcache.memory_consumption is 128M. Even when this isn't used, the virtual memory to track the shared memory(shmem) segment seems to add 2MB extra per **independent** php process in "shared memory" segments, reducing the free RAM available for other processes. (starting a large number of php CLI scripts that sleep() in a loop, `free` (linux program to report free memory) reports that `shared` increases by 2MB per process without opcache.no_cache, but barely increases with opcache.no_cache=1 `opcache.no_cache` takes precedence over `opcache.file_cache*` settings. (If enabled, neither the shared memory cache nor the file cache will be used. It is an error to use both opcache.no_cache and opcache.preload.) On an unrelated PR php#5097 (comment) dstogov mentioned that > Also, it would be great to move optimizer and JIT into core, to make them > available even without opcode caching. This PR is one potential approach for making the optimizer and JIT available without opcode caching. - Even if everything except caching was moved into core, It would still be useful to have a configurable way to disable opcode caching via a system ini setting (`php -d opcache.no_cache=1 my_script.php`) This is currently a proof of concept - feel free to point out combinations of settings that should be rejected. Potential areas for future work: - Normally, opcache optimizes a file based only on that one file's contents. When `opcache.no_cache=1` is used, it may be possible to use all of the class, function, constant, etc. definitions parsed from previously parsed files (to eliminate dead code, inline function calls, etc).
efeaf13
to
eac3998
Compare
I forgot to close this after the RFC vote was declined. https://wiki.php.net/rfc/opcache.no_cache#move_optimizer_and_jit_into_core_instead seems promising according to the poll, but would require a lot of refactoring and deep familiarity with how opcache is used/meant to be used in NTS, ZTS (threaded), etc, and some design work on making the APIs continue to work with tooling that conflicts with opcache or requires that optimizations be disabled. |
RFC: https://wiki.php.net/rfc/opcache.no_cache
Currently, it isn't possible to enable optimizations without enabling caching.
They should be orthogonal features - it's already possible to cache without
optimization passes (
opcache.optimization_level=0
)(In use cases such as running a web server in apache,
it's very desirable to both cache and optimize opcodes.
For short-lived cli scripts, either file_cache or disabling opcache
(to reduce optimization overhead) is often useful.
In a few use cases, it's desirable to optimize without any caching)
Being forced to either enable shared memory caching or file_cache_only
causes these problems:
For file_cache_only, users would be forced to manage the file cache.
(Concerns include running out of disk space, needing to clear stale entries,
concerns about opcode corruption or opcodes for the wrong file contents
not being fixed after restarting a process, etc)
The shared memory block uses up a lot of RAM when individual PHP processes
are known to be long-lived and don't have a common memory address space.
(e.g. multiple long-lived php scripts managed by something that is not
a php script (e.g.
supervisord
, daemons, tools run in the background inIDEs, etc))
The opcodes are duplicated in shmem, which wastes memory in use cases
where opcodes are stored in the cache but never retrieved.
The default for opcache.memory_consumption is 128M.
Even when this isn't used, the virtual memory to track the shared
memory(shmem) segment seems to add 2MB extra per independent php process in
"shared memory" segments, reducing the free RAM available for other processes.
(starting a large number of php CLI scripts that sleep() in a loop,
free
(linux program to report free memory) reports thatshared
increases by 2MB per process without opcache.no_cache, but barely increases
with opcache.no_cache=1
opcache.no_cache
takes precedence overopcache.file_cache*
settings.(If enabled, neither the shared memory cache nor the file cache will be used.
It is an error to use both opcache.allow_cache=0 and opcache.preload.)
On an unrelated PR #5097 (comment)
dstogov mentioned that
This PR is one potential approach for making the optimizer and JIT available
without opcode caching.
It would still be useful to have a configurable way to disable opcode caching
via a system ini setting (
php -d opcache.allow_cache=0 my_script.php
)Feel free to point out combinations of settings that would be errors
Potential areas for future work:
When
opcache.allow_cache=0
is used, it may be possible to use all of theclass, function, constant, etc. definitions parsed from previously parsed
files (to eliminate dead code, inline function calls, etc).
RFC Changelog:
0.2: Change from opcache.no_cache=1 to opcache.allow_cache=0 to avoid double negatives in ini settings