[ovs-dev] [PATCH] [python] Avoid alloc of an attr dict/row+column

Timothy Redaelli tredaelli at redhat.com
Wed Oct 13 14:34:48 UTC 2021

On Tue, 12 Oct 2021 14:13:31 -0500
Terry Wilson <twilson at redhat.com> wrote:

> 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 at redhat.com>

It reduce the memory usage and it's also faster:


0.7460950060049072 (w/o patch) vs 0.6909653190232348 (with patch)

[data.Atom.default(ovs.db.types.ATOMIC_TYPES[1]) for x in


322605613 bytes (w/o patch) vs 114605277 bytes (with patch)

Acked-by: Timothy Redaelli <tredaelli at redhat.com>
Tested-by: Timothy Redaelli <tredaelli at redhat.com>

More information about the dev mailing list