3 ms·
It's an implementation issue. I posted this as a comment to the article: -- I'm working on a Ruby compiler and have taken pretty much [the PyPy] approach [of
by vidarh 13y ago
It's an implementation issue.
I posted this as a comment to the article:
--
I'm working on a Ruby compiler and have taken pretty much [the PyPy] approach [of automatically using slots when possible]: Any instance variable names I can statically determine are candidates for the equivalent treatment (allocating a slot at a fixed offset in the object structure).
Anything else will still go in a dictionary. In practice my experience is that a huge proportion of objects will have a fairly static set of attributes, and the dynamic set is often small enough that having pointers them included in every instance is still often cheaper than using dictionaries.
---
In a static language, your options are generally to either statically allocate slots, or explicitly use a dictionary anyway.
- PythonicAlpha 13y agoYou are right. But the normal application of Python is in circumstances, where you are not under such pressure anyway and flexibility and ease of use is more a requirement than having maximum speed or minimal memory requirements. And of course it is particularly the CPython implementation that I described ... but CPython is still the implementation that is used most and the one where most enhancements, libraries and so exist. Other implementations might do better in many ways, but what made Python great, is still available in its original form, the CPython environment.