peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.64k stars 238 forks source link

slot widgets for performance and memory improvment #213

Closed jabdoa2 closed 5 years ago

jabdoa2 commented 5 years ago

Issues fixed by this PR

None

What does this implement/fix?

Improve performance of widget creation in Python 3 by slotting widgets.

coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.01%) to 96.301% when pulling 46f896e69ffb364f3b633c97a37b2b669e3c8bdc on jabdoa2:slot_widgets into 3c3267a76cd57bbe8df711c86743c96f819ac47a on peterbrittain:master.

peterbrittain commented 5 years ago

Interesting... As I understood it, use of slots gives you a marginal performance and occupancy benefit. I hadn't done anything with it up to now as I didn't think it warranted the extra effort of synchronizing the list with the code to initialize it. What sort of gains did you get in making this change?

jabdoa2 commented 5 years ago

We get 3-4% of worst case CPU improvements from this. This mostly reduces the memory footprint of objects because they won't use a dict but a fixed position for the attributes. As a result access times are shorter. However, I guess in this case reduced memory footprint has the largest effect (because we create a lot of Labels). PYPY does this automatically but Python does not.