Skip to content

Commit

Permalink
ASCWriter speed improvement
Browse files Browse the repository at this point in the history
Changed how the message data is converted to string. This results in and 100% speed improvement.

On my PC, before the change, logging 10000 messages was taking ~16 seconds and this change drop it to ~8 seconds. With this change, the ASCWriter is still one of the slowest writer we have in Python-can.
  • Loading branch information
pierreluctg authored Sep 12, 2024
1 parent 7302127 commit b1a2997
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions can/io/asc.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ def on_message_received(self, msg: Message) -> None:
return
if msg.is_remote_frame:
dtype = f"r {msg.dlc:x}" # New after v8.5
data: List[str] = []
data: str = ""
else:
dtype = f"d {msg.dlc:x}"
data = [f"{byte:02X}" for byte in msg.data]
data = msg.data.hex(" ").upper()
arb_id = f"{msg.arbitration_id:X}"
if msg.is_extended_id:
arb_id += "x"
Expand All @@ -462,7 +462,7 @@ def on_message_received(self, msg: Message) -> None:
esi=1 if msg.error_state_indicator else 0,
dlc=len2dlc(msg.dlc),
data_length=len(msg.data),
data=" ".join(data),
data=data,
message_duration=0,
message_length=0,
flags=flags,
Expand All @@ -478,6 +478,6 @@ def on_message_received(self, msg: Message) -> None:
id=arb_id,
dir="Rx" if msg.is_rx else "Tx",
dtype=dtype,
data=" ".join(data),
data=data,
)
self.log_event(serialized, msg.timestamp)

0 comments on commit b1a2997

Please sign in to comment.