Re: Property access slowness
| From: | Sterling Hughes | Date: | Sun, 25 May 2003 14:06:30 +0000 |
| Subject: | Re: Property access slowness | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-1988@lists.php.net to get a copy of this message | ||
On Sun, 2003-05-25 at 10:57, Zeev Suraski wrote:
> At 15:58 25/05/2003, Sterling Hughes wrote:
> >On Sun, 2003-05-25 at 04:24, Zeev Suraski wrote:
> > > At 19:15 24.05.2003, Sterling Hughes wrote:
> > > >Hi,
> > > >
> > > >Property access with PHP5 is very slow compared to PHP4. The reason for
> > > >this is that property access must be verified *every* time. This seems
> > > >really unnecessary unless we're indirectly accessing properties.
> > >
> > > It has to be verified each time, because we're typeless, and can't do
> > stuff
> > > like that in compile time. It's not related to indirect reference...
> > >
> >
> >Ahh, yeah. Can we at least embed property information within the
> >ce->properties hashtable? Currently accessing properties in PHP5 is
> >*15%* slower. Denormalizing the properties_info, should give a nice
> >performance gain.
>
> There's no ce->properties, it sits in each object instance, so not
> really... We could possibly look into some optimization along the lines of
> what Alan suggested. I haven't given it much thought, but apparently, if a
> class and its entire ancestors tree doesn't use PPP - it may be possible to
> save the get_property_info call.
> Remember that in general, the fact that property access is slower is no
> news - we know it would be. The gain in reduced copying should buy us some
> performance, though.
>
I'm must be going senile then :) Let zobj be an object zval.
zobj->properties and zobj->ce->properties_info is what I'm talking
about.
When object properties are looked up, via read_property(), first a
hashtable access is done on zobj->ce->property_info, to find the
property access levels, then the property access levels are verified.
Then the lookup is done on zobj->properties to find the property value,
and we are all happy.
A first time lookup is fine, but per-object this need not be looked up
and verified more than once. Therefore, if we change each individual
property to contain an extra field, verified, we can save this check
each time the object property is accessed. Something like:
struct obj_property {
zval *value;
int verified;
};
Where the verified state is maintained per-object, we should be able to
cut repeated accesses down to nothing. Unless I'm missing something?
-Sterling
> Zeev
--
"That stuff's easy compared to installing Horde"
- Alan Knowles, In response to my applause for creating a LALR
parser for PHP.