Objects, attributes, maps, oh my

26 points by priime


xnacly

i fucking love maxes website, currently rereading his ssa and his linear regalloc articles again, can only recommend

lightandlight

It'd also be worth checking "Smalltalk-80: The Language and its Implementation" to see how/whether Smalltalk handles this.

dutc

This is an interesting overview.

It is a bit surprising that the author doesn't mention the __slots__ optimisation (which, in my opinion, is largely very uninteresting… except perhaps for investigations like this one.)

This is one way that actual CPython handles the performance penalty of attribute access. (The CPython interpreter also has various caches—example—to reduce this penalty, and Python codes, as a general principle, tend to evolve toward so-called “restricted computation domain” heterogeneous execution that side-steps the limitations the author highlights.)

Additionally, there are optimisations on the dict type that should be relevant here, such as the PEP-412 key-sharing dictionary. There are also some “hidden” optimisations in the language that have inadvertently become semantics—e.g., tp_ method resolution doesn't follow the standard protocols, which is why C-level protocol methods cannot be intercepted by __getattr__ but others can be.

I suspect much of the same (except heterogeneous execution) to be the same for Javascript, except substantially more sophisticated and more optimised in its implementation. (After all, I have heard well-informed estimates that Javascript has received as many as two or three orders of magnitude more dollar-value investment in its development!) I suspect that few of these choices have affected semantics, since Javascript never seemed very interested in semantic consistency (unlike Python which is surprisingly and pleasingly consistent for something with such ad hoc design!)… The Javascript interpreter developers also have to contend with their audience of users and the enormous body of very low-quality and low-sophistication codes that they may be very hesitant to break. (At least, in my experience, many people learn Javascript like they learn SQL or Bash, so it seems very common for well-designed, neat new features to be skipped in lieu of whatever the language looked like in whatever form the author first encountered it…)