2 ms·
> Roughly 85% of LOAD_ATTRs occured at monomorphic sites; This observation and the accompanying graph are, I think, the "generational hypothesis" equivalent to
by munificent 8y ago
> Roughly 85% of LOAD_ATTRs occured at monomorphic sites;
This observation and the accompanying graph are, I think, the "generational hypothesis" equivalent to static types.
The generational hypothesis says most objects are either very short-lived or long-lived and modern generation GCs very effectively optimize for that fact.
A particularly pragmatic way to look at static types is that they optimize for monomorphic calls at the expense of polymorphic calls. For the latter, they require you to manually define interfaces, virtual methods, or some other explicit dynamism. In return, monomorphic calls are much faster.
The 85% number is an indication that that's a good optimization, as long as the other 15% aren't too hard to handle in your statically-typed language.
- xapata 8y agoOr you can just do what Python 3.7 implemented (and Instagram seems to have separately implemented) -- cache attribute lookups and invalidate the cache if necessary. [0] The GC optimization, well, that'll probably be left up to other interpreters. [0] "Mark Shannon said that Python 3.7 has added a feature that should provide a similar boost as the method-lookup caching used in the experiment. Shapiro said he had looked at those changes but still believed his proposed mechanism would provide more benefit. Attribute lookup still requires five lookups in CPython, while it is only one lookup in the experimental version. Shannon did not sound entirely convinced of that, however." https://lwn.net/Articles/754163/ https://lwn.net/Articles/754163/