On Tue, 12 Oct 2021 14:13:31 -0500 Terry Wilson <[email protected]> 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 <[email protected]> It reduce the memory usage and it's also faster: print(min(timeit.repeat(lambda: data.Atom.default(ovs.db.types.ATOMIC_TYPES[1])))) 0.7460950060049072 (w/o patch) vs 0.6909653190232348 (with patch) [data.Atom.default(ovs.db.types.ATOMIC_TYPES[1]) for x in range(1000000)] print(guppy.hpy().heap()) 322605613 bytes (w/o patch) vs 114605277 bytes (with patch) Acked-by: Timothy Redaelli <[email protected]> Tested-by: Timothy Redaelli <[email protected]> _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
