From ec4cd4101f9b02c96aef79b26bf8f5e1e6ee696a Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 16 Sep 2024 16:10:26 +0200 Subject: [PATCH] topotato: use `__slots__` on `TimedElement` A lot of `TimedElement` are created and passed around during a normal topotato run. Use `__slots__` to make them a bit more efficient. Signed-off-by: David Lamparter --- topotato/frr/core.py | 10 ++++++++++ topotato/frr/livelog.py | 13 +++++++++++++ topotato/livescapy.py | 4 ++++ topotato/timeline.py | 4 ++++ 4 files changed, 31 insertions(+) diff --git a/topotato/frr/core.py b/topotato/frr/core.py index 901635c..1f3c467 100644 --- a/topotato/frr/core.py +++ b/topotato/frr/core.py @@ -348,6 +348,16 @@ class TimedVtysh(TimedElement): This is used to know when to stop running the Timeline event poller. """ + __slots__ = [ + "_ts", + "rtrname", + "daemon", + "cmd", + "retcode", + "text", + "last", + ] + # pylint: disable=too-many-arguments def __init__( self, diff --git a/topotato/frr/livelog.py b/topotato/frr/livelog.py index 359d38b..a0899c7 100644 --- a/topotato/frr/livelog.py +++ b/topotato/frr/livelog.py @@ -111,6 +111,19 @@ class LogMessage(TimedElement): router: "FRRRouterNS" daemon: str + __slots__ = [ + "header_fields", + "arghdrlen", + "args", + "rawtext", + "text", + "uid", + "_ts", + "_prio", + "router", + "daemon", + ] + # mypy doesn't work with dynamic namedtuple @typing.no_type_check def __init__(self, router: "FRRRouterNS", daemon: str, rawmsg: bytes): diff --git a/topotato/livescapy.py b/topotato/livescapy.py index 31e56fc..8771e73 100644 --- a/topotato/livescapy.py +++ b/topotato/livescapy.py @@ -20,6 +20,10 @@ class TimedScapy(TimedElement): + __slots__ = [ + "_pkt", + ] + def __init__(self, pkt): super().__init__() self._pkt = pkt diff --git a/topotato/timeline.py b/topotato/timeline.py index d7a003a..bf2ea7b 100644 --- a/topotato/timeline.py +++ b/topotato/timeline.py @@ -221,6 +221,10 @@ class TimedElement(ABC): If this object satisfied some test condition, the test item is recorded here. """ + __slots__ = [ + "match_for", + ] + def __init__(self): super().__init__() self.match_for = []