Skip to content

Commit 61e8f6f

Browse files
author
Pierre-Luc Tessier Gagne
committed
perf(neovi): drop redundant int casts in NetworkID packing
Root cause: `send()` converted expressions to `int(...)` even though bitwise operations on Python ints already produce ints. The extra calls add tiny but unnecessary overhead in a transmit hot path. Implemented solution: - Replace: `int(network_id & 0xFF), int((network_id >> 8) & 0xFF)` with: `network_id & 0xFF, (network_id >> 8) & 0xFF` Rationale vs alternatives: This is a no-risk micro-optimization and cleanup with identical semantics. Performance evidence: - Evidence type: Python operation semantics and call-overhead analysis. - Expected impact: Low but positive for high-frequency sends. Test methodology: - Session functional validation: `python -m pytest test/test_neovi.py` -> passed. Assumptions, limitations, risks: - `network_id` remains integer-valued as enforced by existing channel parsing. Potential follow-ups: - Include send-heavy throughput profiling to quantify aggregate impact. Other identified optimizations not implemented in this commit: - Additional zero-copy opportunities require ICS API support.
1 parent d7ca7d2 commit 61e8f6f

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

can/interfaces/ics_neovi/neovi_bus.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,7 @@ def send(self, msg, timeout=0):
532532
else:
533533
raise ValueError("msg.channel must be set when using multiple channels.")
534534

535-
message.NetworkID, message.NetworkID2 = int(network_id & 0xFF), int(
536-
(network_id >> 8) & 0xFF
537-
)
535+
message.NetworkID, message.NetworkID2 = network_id & 0xFF, (network_id >> 8) & 0xFF
538536

539537
if timeout != 0:
540538
msg_desc_id = next(description_id)

0 commit comments

Comments
 (0)