3 ms·
Strange that Guido or the other CPython devs would object to adding caching (though, rereading, maybe they only objected to the tone it was presented in - which
by eximius 8y ago
Strange that Guido or the other CPython devs would object to adding caching (though, rereading, maybe they only objected to the tone it was presented in - which still seems a bit sensitive). I get favoring simple code over optimizations for more extreme cases like switching from dictionaries to arrays, but what essentially sounds like a tiny LRU cache for method dispatch seems like a clear win for everyone.
- myWindoonn 8y agoCPython has always strived to be a simple easy-to-read reference implementation of Python. They have rejected many patches over the decades which would have sped up various things at the expense of readability. People should not use CPython for speed; they should use PyPy for speed.
- neuland 8y agoThe article did mention that Instagram's code wasn't much faster on PyPy. I agree with you though; one of the interesting and good things about Python is that it's a standard not an implementation. Although CPython is the the most popular by usage, PyPy and Cython are mainstream alternatives (or superset in the case of cython). There's also Jython, IronPython, Unladen Swallow, Grumpy, and others that I can't think of now. Some of those are defunct and others only are Python 2. But the point is, competition is good.
- eximius 8y agoAnd it is simple. I haven't written C since college and it's mostly very readable, really great for exploration. In many ways, I agree that should be kept. But memoizing lookups can be a single branch at the top of a few functions. We should strive to have our cake and eat it too, not simply declare we shouldn't bother.
- xapata 8y agoIt ain't that easy (cache invalidation is hard). But they did it anyway, so, yeah, you can have your cake and eat it.
- carapace 8y agoYes, or Cython or Nuitka. And keep an eye on the (poorly named) Grumpy project (Python compiled to Go.) http://cython.org/ http://cython.org/ https://nuitka.net/ https://nuitka.net/ https://github.com/google/grumpy https://github.com/google/grumpy
- xapata 8y agoA version of attr-lookup caching is already added in 3.7. Thus Guido objected to the tone of, "I'm the first person to notice this!" > 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. As I understand it, class-attribute dicts now carry a version number which increments on every mutation. The first method lookup gets cached and subsequent lookups check the version number to decide whether to invalidate the cache.