Re: [RFC] Lazy Objects
| From: | Tim Düsterhus | Date: | Fri, 05 Jul 2024 19:58:41 +0000 |
| Subject: | Re: [RFC] Lazy Objects | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-124235@lists.php.net to get a copy of this message | ||
Hi
On 7/2/24 17:49, Arnaud Le Blanc wrote:
Your Gists don't seem to include the actual numbers, so the second link is not particularly useful. However you said that using a backed enum does not improve the situation, so there probably really is not much that can be done. For completeness I want to note, though: You might be able to improve the type checking performance by directly checking the CE instead of going throughI'm curious, how did the implementation look like? Is there a proof of concept commit or patch available somewhere? As the author of the first internal enum (Random\IntervalBoundary) I had the pleasure of finding out that there was no trivial way to efficiently match the various enum cases. See the PR review here: https://github.com/php/php-src/pull/9679#discussion_r1045943444I've benchmarked this implementation: https://github.com/arnaud-lb/php-src/commit/f5f87d8a7abeba2f406407606949e5c6e512baab. Using a backed enum to have a more direct way to map enum cases to integers didn't make a significant difference. Here is the benchmark: https://gist.github.com/arnaud-lb/76f77b5d7409a9e4deea995c179c6e96. Caching the options array between calls had a less dramatic slowdown (around 10%): https://gist.github.com/arnaud-lb/87e7f58cc11463dd3aa098218eb95a90.
instanceof_function(), because you know that inheritance is not a thing for enums. Not sure if this makes much of a difference, given the fact that instanceof_function() already does this and is force-inlined, but it might remove the branch with the call to instanceof_function_slow().
Best regards
Tim Düsterhus