Re: [PATCH] No runtime fetching of built-in global constants
| From: | Dmitry Stogov | Date: | Fri, 29 Aug 2008 09:19:21 +0000 |
| Subject: | Re: [PATCH] No runtime fetching of built-in global constants | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-40126@lists.php.net to get a copy of this message | ||
Hi Matt,
I updated your patch a little bit to make it more clear (from my point
of view).
Please take a look.
Thanks. Dmitry.
Matt Wilmas wrote:
> Hi Dmitry,
>
> Well, it's been awhile since Alpha 1 :-), so I wanted to finally resend this
> before Alpha 2! I agree that the additional optimization probably wouldn't
> happen often, as there won't be that much namespace usage right away, I
> assume. But I think it makes sense to handle :: prefix constants, since
> they're known to have global scope, and I can see the future [online]
> optimization tip: "When using namespaces, use :: for global constants to get
> compile-time substitution." ;-)
>
> The code is the same as before, just updated the patch. It doesn't really
> seem less clear, to me, than the current code. In zend_do_fetch_constant(),
> the "check_namespace" variable may be better named something like
> "from_namespace" according to my changes, to be more clear, but I left that
> out to make the patch as simple as possible.
>
> http://realplain.com/php/ct_const_fixes.diff
> http://realplain.com/php/ct_const_fixes_5_3.diff
>
>
> Thanks,
> Matt
>
>
> ----- Original Message -----
> From: "Dmitry Stogov"
> Sent: Thursday, July 31, 2008
>
>> Hi Matt,
>>
>> Now I know. :)
>> Anyway, I don't think this optimization will work often.
>>
>> Send me the patch after Alpha1 release.
>>
>> Thanks. Dmitry.
>>
>>
>> Matt Wilmas wrote:
>>> Hi Dmitry,
>>>
>>> Do you know that with your changes, no substitution will happen in a
>>> namespace even when using :: prefix? :-/ (That's what I would do when I
>>> know it's global, for optimization.) Or is that what you meant by "not
> so
>>> optimal?"
>>>
>>>
>>> - Matt
>>>
>>>
>>> ----- Original Message -----
>>> From: "Dmitry Stogov"
>>> Sent: Thursday, July 31, 2008
>>>
>>>> Thanks Matt. I committed near the same patch.
>>>> It's not so optimal, but little bit more clear.
>>>>
>>>> Thanks. Dmitry.
>>>>
>>>> Matt Wilmas wrote:
>>>>> Hi Dmitry,
>>>>>
>>>>> For the behavior change that I mentioned in the other thread, with
> this
>>>>> code:
>>>>>
>>>>> function foo() {
>>>>> static $a = -PHP_INT_MAX;
>>>>> }
>>>>>
>>>>> Which could work sometimes, and sometimes not (if in a namespace or
>>>>> ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION is set). I changed things so
> that
>>>>> there is no substitution of constants (except with CT_SUBST flag, like
>>>>> always) for compile time constants (ZEND_CT mode). They don't create
> a
>>>>> FETCH_CONSTANT opcode anyway. :-)
>>>>>
>>>>> Another thing I realized wasn't getting optimized (runtime constants),
>>> which
>>>>> can be, is with:
>>>>>
>>>>> namespace foo;
>>>>> $a = ::PHP_INT_MAX; // :: for global scope
>>>>>
>>>>> So the patch allows substitution there as well.
>>>>>
>>>>> http://realplain.com/php/ct_const_fixes.diff
>>>>>
>>>>> http://realplain.com/php/ct_const_fixes_5_3.diff
>