<#13749 Scope work required to enable `__slots__` ...
# github-notifications
q
#13749 Scope work required to enable `__slots__` and estimate performance benefits Issue created by chrisjrn Declaring the
__slots__
attribute in Python classes makes those classes use a more efficient attribute lookup mechanism, provided the attributes on instances are known in advance. See Python docs (Python 3.10 linked, but has been available since 2.2). #9469 investigated using
__slots__
from a memory saving perspective, but did not investigate runtime performance, and was deferred at the time due to concerns of adding too much boilerplate. Work in #13661 introduced
__slots__
into the JVM artifact mapping trie for runtime performance reasons. @witty-crayon-22786 mentioned in #13697 that #12662 may benefit from this work in future. Adopting
__slots__
universally in Pants is not trivial: • `dataclass`es do not work with
__slots__
prior to Python 3.10, especially when default values are provided •
frozen_after_init
adds extra attributes to the class, which needs to behave cleanly when
__slots__
are defined in decorated classes There are likely other concerns here, but these are the two that come to mind first. Scope 1. Figure out what refactoring work is necessary to use
__slots__
throughout the Pants codebase (particularly with respect to `dataclass`es and `frozen_after_init`ed classes) 2. Do part of the work and see if it improves things in the part of the codebase where the optimisation has been tried out. Further discussion @jsirois points out that `attrs` does not have the limitations around `__slots__` that `dataclasses` has, and this may be a worthwhile approach. We'd need to measure performance viz.
dataclasses
before committing. pantsbuild/pants