Re: Small question about performance
| From: | Paul Dragoonis | Date: | Thu, 15 Mar 2012 17:41:24 +0000 |
| Subject: | Re: Small question about performance | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-58967@lists.php.net to get a copy of this message | ||
On Thu, Mar 15, 2012 at 5:39 PM, Paul Dragoonis <dragoonis@gmail.com> wrote:
> On Thu, Mar 15, 2012 at 4:54 PM, Nikita Popov <nikita.ppv@googlemail.com> wrote:
>> On Thu, Mar 15, 2012 at 5:22 PM, Patrick ALLAERT <patrickallaert@php.net> wrote:
>>> 2012/3/15 Nikita Popov <nikita.ppv@googlemail.com>:
>>>> If I am understanding the text correctly it is saying that
>>>> $f1 = f1();
>>>> $f2 = f2($f1);
>>>> $f3 = f3($f2);
>>>> is using more memory than
>>>> $f3 = f3(f2(f1()));
>>>>
>>>> For me this doesn't make any sense. In the latter case PHP will also
>>>> create temporary variables to store the return values. There should be
>>>> no difference in memory consumption.
>>>
>>> It does make sense to me.
>>>
>>> In the first case, when calling f3(), $f1 is still referenced.
>>> In the second case, when calling f3(), the result of f2() is
>>> referenced, but there is no more active reference to the result of
>>> f1().
>> I don't really know when PHP frees temporary variables, but my guess
>> was that they are freed when the scope is left.
>
> Each variable has a refcount, then that hits 0 it can be freed up.
To add to that. A zval will have a refcount, so if you do $a =
someFunc(); then $a will have a refcount.
If you do something like $a = someFunc(anotherFunc(moreFunc())), the
return values of anotherFunc() and moreFunc() will be temp stored, but
they will _not_ have a refcount because they never got assigned into a
zval like $a.
Hope that made sense.
>
>>
>> If that is not true, then forget whatever I said.
>>
>> But if it is true, then there is no inherent difference between the
>> two version. The only difference is that explicit $variables would
>> need an entry in the active symbol table, which is pretty much
>> negligible.
>>
>> --
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>