-
Notifications
You must be signed in to change notification settings - Fork 7.9k
opcache: optimize some more functions on compile time #5870
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
- dirname(string[, int]) - md5(string) - crc32(string) - sha1(string) - array_unique(array) - array_filter(array) - basename(string[, string])
EDIT: looks like you have removed the hash functions I was concerned about now. 👍 |
I am 👍 for |
In PHP 8 and probably 7, I think that array_unique with 2 args is of complexity See ext/standard/array for I'd agree that code needing to use array_unique is uncommon, but not impossible. For example, (timing strangeness possibly due to cache locality or the time being amortized and not accounting for resizing, but it isn't quadratic)
|
- don't optimize basename(), version_compare(string, string, string) - optimize strtolower(string), strtoupper()
98e5128
to
794c5fb
Compare
- don't optimize basename(), version_compare(string, string, string)
Onother live example for the dirname() optimization: Symfony dumped DIC |
I think your updated proposed list of functions looks much better, now. 👍 |
Sorry for the delay! I finally got around to rewriting this code, as the current approach seemed unnecessarily fragile (see the version_compare case found here). I have added support for throwing functions (we will simply discard the exception), so we only need to check for functions/args that are runtime dependent or can result in warnings, now done in this function: php-src/ext/opcache/Optimizer/sccp.c Line 784 in 99a3dbc
Would you mind rebasing on top of these changes? I think it should now be just a matter of adding functions to the list, without the need to add any new logic. |
Those changes introduced some differences in behavior due to opcache always evaluating the code with Obviously, logic for array_filter would need to be kept to check if there were 1 arguments - the callback has side effects The argument counts/types for str_replace should also continue to need to be checked for arrays within arrays because those would emit notices during compilation EDIT: Should also continue to check that there are 3 parameters for
|
I've added array_unique and str_replace from here in 273720d. dirname has already been added earlier (for non-Windows). |
I profiled our production code and found some (more or less rare) function calls which could get evaluated on compile time already + extended it by some other function calls which should always return a static result.
List: (updated one)
Dummy code:
Opcodes before:
Opcodes afterwards: