data: Define __slots__ for core classes.

Because these are the classes that get instantiated many times while
iterating transactions, the performance benefit of defining __slots__
is worth the development overhead.
This commit is contained in:
Brett Smith 2020-03-31 15:00:15 -04:00
parent fd2830f483
commit 3aee1efdc1

View file

@ -62,6 +62,8 @@ class Account(str):
or Income:Donations. This class provides additional methods for common
account name parsing and queries.
"""
__slots__ = ()
SEP = bc_account.sep
def is_checking(self) -> bool:
@ -115,6 +117,7 @@ class Metadata(MutableMapping[MetaKey, MetaValue]):
This class wraps a Beancount metadata dictionary with additional methods
for common parsing and query tasks.
"""
__slots__ = ('meta',)
def __init__(self, source: MutableMapping[MetaKey, MetaValue]) -> None:
self.meta = source
@ -165,6 +168,7 @@ class PostingMeta(Metadata):
Under the hood, this class does a little extra work to avoid creating
posting metadata if it doesn't have to.
"""
__slots__ = ('txn', 'index', 'post')
def __init__(self,
txn: Transaction,
@ -207,6 +211,7 @@ class Posting(BasePosting):
* The `account` field is an Account object
* The `meta` field is a PostingMeta object
"""
__slots__ = ()
account: Account
# mypy correctly complains that our MutableMapping is not compatible