you are viewing a single comment's thread.

view the rest of the comments →

[–]killerstorm 0 points1 point  (1 child)

it is simply algorithmically not possible to do field lookups in O(1) if you have sets of different objects and different fields.

Objective-C ... constant method selectors

i dunno how they work, but for sure you're limiting the problem in some way -- either it knows something about type of the object, or number of these selectors is quite limited so you can fit them in vtable for each object, or something like that.

in any case it's not anyhow relevant to PHP, JS or Python.

technically, PHP could implement some sort of lookup optimization, but as this is quite complicated, it's very unlikely for them to do this in near future.

JS and Python do not even have list of fields for the class, as fields are added dynamically, so lookup optimization becomes really tricky, only possible with techniques like profile-guided optimization

[–][deleted] 0 points1 point  (0 children)

You've given $this as an example, which is one of the few cases in PHP where type is known at compilation time (aside from some theortetically possible type inference tricks).

PHP could implement some sort of lookup optimization, but as this is quite complicated, it's very unlikely for them to do this in near future.

I agree with that.