Skip to content

Commit

Permalink
topotato: use __slots__ on TimedElement
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
eqvinox committed Sep 17, 2024
1 parent f0ee9c9 commit ec4cd41
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions topotato/frr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions topotato/frr/livelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions topotato/livescapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@


class TimedScapy(TimedElement):
__slots__ = [
"_pkt",
]

def __init__(self, pkt):
super().__init__()
self._pkt = pkt
Expand Down
4 changes: 4 additions & 0 deletions topotato/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit ec4cd41

Please sign in to comment.