You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Proposal] opcache.no_cache: Opcode optimization without caching
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).
0 commit comments