mirror of
https://github.com/openvswitch/ovs
synced 2025-10-17 14:28:02 +00:00
python: db: Avoid allocation of an attr dict/row+column.
Python objects normally have a dictionary named __dict__ allocated for handling dynamically assigned attributes. Depending on architecture and Python version, that empty dict may be between 64 and 280 bytes. Seeing as Atom and Datum objects do not need dynamic attribute support and there can be millions of rows in a database, avoiding this allocation with __slots__ can save 100s of MBs of memory per Idl process. Signed-off-by: Terry Wilson <twilson@redhat.com> Acked-by: Timothy Redaelli <tredaelli@redhat.com> Tested-by: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
committed by
Ilya Maximets
parent
695530d8fb
commit
04b017e3a2
@@ -64,6 +64,8 @@ def returnUnchanged(x):
|
||||
|
||||
@functools.total_ordering
|
||||
class Atom(object):
|
||||
__slots__ = ('value', 'type')
|
||||
|
||||
def __init__(self, type_, value=None):
|
||||
self.type = type_
|
||||
if value is not None:
|
||||
@@ -266,6 +268,8 @@ class Atom(object):
|
||||
|
||||
@functools.total_ordering
|
||||
class Datum(object):
|
||||
__slots__ = ('type', 'values')
|
||||
|
||||
def __init__(self, type_, values={}):
|
||||
self.type = type_
|
||||
self.values = values
|
||||
|
Reference in New Issue
Block a user