On Apr 21, 2012, at 2:19 PM, Boris Zbarsky wrote:
> On 4/21/12 5:07 PM, David Herman wrote:
>> Also, I could imagine this might tax enumeration, since it has to go through the OrderMap indirection. But if this made ordinary property accesses faster, maybe it'd be worth it? Again, I'm probably embarrassing myself showing off my ignorance. But that'd be nothing new. :-P
>
> This would only make ordinary property access faster if we kept the invariant that a Shape determines the names corresponding to the slots of an object, right? And that would mean that property addition would need to memmove the slots array around as needed, because instead of just putting the new prop at the end we'd need to put it somewhere in the middle, in general.
Ah right, very good point.
> And _that_ would make adding N properties to an object take O(N^2) time, unless I'm missing something.
Yeah, that sounds right.
> That might be OK, since N is typically small, and we could "deoptimize" to just adding at the end for large N...
>
> Plus of course having to maintain the order map. The upshot would be possibly faster property reads and somewhat slower property additions, right? Might be interesting to measure.
Yeah, the set of things I don't know here is quite large, including (but not limited to):
- would this actually lead to faster property reads?
- does it make sense to favor reads over writes? my preferred style of programming says yes, but I have no illusions that everyone likes to program like me
- does the web actually have a lot of shape duplication due to accidental property order disagreement?
Andreas suggested I could measure the latter question fairly easily by printing out a bunch of shape trees for real-world web pages. That's something we could measure without having to implement any new object representations, at least. Maybe next week I can get someone to show me how to do that measurement.
Thanks,
Dave