Re: PHP 5.1 vm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, July 5, 2005 10:55 pm, Dan Rossi said:
>
> On 06/07/2005, at 3:43 PM, Rasmus Lerdorf wrote:
>
>> The SWITCH vm was originally just a big switch(opcode) { case 1: ...;
>> case 2: ...' } It's a bit different now, but you can think of it in
>> those terms.  Decent compilers should theoretically be able to optimize
>> a clean set of cases to something close to simple branches, just like
>> the computed goto case, but it can be hit and miss.  With the computed
>> goto way of doing it, we are trying to send a stronger hint to the
>> compiler.
>
> Well i do find a performance issue running a heap of switches in PHP so
> I could presume the same here.

I believe that what's supposed to happen, in theory, is that the compiler
*CONVERTS* the swith statement to a bunch of GOTOs behind the scenes.

At least I think that's what Rasmus means by "simple branches" -- GOTOs.

When this works, you get the speed of GOTOs with the syntactic sugar of
SWITCH for us humans to look at. :-)

>> And finally the CALL vm basically just uses a function pointer to call
>> the handling code.  Think of it as something alone the lines of
>> ${"handler_$i"}(); in PHP terms.  That is, you would have handler_1(),
>> handler_2(), handler_3() functions defined and you dynamically
>> determine
>> which one to call based on the opcode.
>
> Ahh like a dynamic callback interesting, I would prob find this the
> quickest then ? I do find it more efficient to run callback functions
> than switches in the php code which I have been doing for a while now.

I suspect that in C and low-level PHP, the SWITCH would generally be
faster than the callback because of overhead...

Not sure why the PHP switch would be "slower" than callbacks in your
experience...  That could easily be more about the rest of the code
surrounding the switch/callback rather than the switch/callback choice
itself...

Or maybe PHP's switch is just dog-slow...  Seems real unlikely, but
stranger things have happened.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux