Changeset - 3aee1efdc1ad
[Not reviewed]
0 1 0
Brett Smith - 4 years ago 2020-03-31 19:00:15
brettcsmith@brettcsmith.org
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.
1 file changed with 5 insertions and 0 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/data.py
Show inline comments
...
 
@@ -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
0 comments (0 inline, 0 general)