Re: Object getter method optimization
| From: | Nikita Nefedov | Date: | Sun, 20 Mar 2016 08:52:05 +0000 |
| Subject: | Re: Object getter method optimization | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-91785@lists.php.net to get a copy of this message | ||
On Sat, 19 Mar 2016 23:40:09 +0300, Andrea Faulds <ajf@ajf.me> wrote:
Hi Lin, Lin Yo-An wrote:I was playing with this idea sometime ago, it gives good performance boost for code likeSince the original approach doesn't work, here comes another new idea: When executing method call on an object, if we found the method body are just 2 op codes (FETCH_OBJ_R and RETURN), we then denote the method is a "getter method" And the next time, when we execute the same method, we found the "getter method" flag, we simply execute FETCH_OBJ_R on that object and return the value to avoid extra op code execution time. Do you think if this could work?For a while I'd also been wondering if we could implement some implementation along these lines. Another approach could be possibly replacing such methods with an C implementation (though I don't know if non-internal classes can have internal methods). I don't know how successful it will be, but I'm interested to hear how much improvement it gives if you get it working. Thanks!
for ($i = 0; $i < 100000; $i++) $a->getFoo(); but in the end of the day it's a very limited optimization.
If you abstract away from getters and say you want to optimize more and more small functions like this one, you end up realizing that what you're actually doing is what JIT compilation would do in a more generic way.