Skip to content

Commit

Permalink
CANParser: improve cython performance (commaai#802)
Browse files Browse the repository at this point in the history
* improve cython performance

* change thresholds

* Trigger CI

* reduce threshold for test all signals

* change

* reduce min

* change

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* change

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* change

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI

* Trigger CI
  • Loading branch information
deanlee authored and OPGM CI Automated committed Apr 6, 2023
1 parent 5bcfe8c commit 810f241
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 12 additions & 4 deletions can/parser_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cdef class CANParser:
self.address_to_msg_name[msg.address] = name
self.vl[msg.address] = {}
self.vl[name] = self.vl[msg.address]
self.vl_all[msg.address] = defaultdict(list)
self.vl_all[msg.address] = {}
self.vl_all[name] = self.vl_all[msg.address]
self.ts_nanos[msg.address] = {}
self.ts_nanos[name] = self.ts_nanos[msg.address]
Expand Down Expand Up @@ -111,22 +111,30 @@ cdef class CANParser:
# Cast char * directly to unicode
cv_name = <unicode>cv.name
self.vl[cv.address][cv_name] = cv.value
self.vl_all[cv.address][cv_name].extend(cv.all_values)
self.ts_nanos[cv.address][cv_name] = cv.ts_nanos

vl_all = self.vl_all[cv.address]
if (cv_name in vl_all):
vl_all[cv_name].extend(cv.all_values)
else:
vl_all[cv_name] = cv.all_values

updated_addrs.insert(cv.address)

return updated_addrs

def update_string(self, dat, sendcan=False):
for v in self.vl_all.values():
v.clear()
for l in v.values():
l.clear()

self.can.update_string(dat, sendcan)
return self.update_vl()

def update_strings(self, strings, sendcan=False):
for v in self.vl_all.values():
v.clear()
for l in v.values():
l.clear()

updated_addrs = set()
for s in strings:
Expand Down
8 changes: 4 additions & 4 deletions can/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def test_performance_one_signal(self):
signals = [
("ACCEL_CMD", "ACC_CONTROL"),
]
self._benchmark(signals, [('ACC_CONTROL', 10)], (7800, 15000), 1)
self._benchmark(signals, [('ACC_CONTROL', 10)], (2500, 5000), 10)
self._benchmark(signals, [('ACC_CONTROL', 10)], (5000, 7000), 1)
self._benchmark(signals, [('ACC_CONTROL', 10)], (2200, 3000), 10)

def test_performance_all_signals(self):
signals = [
Expand All @@ -65,8 +65,8 @@ def test_performance_all_signals(self):
("ACCEL_CMD_ALT", "ACC_CONTROL"),
("CHECKSUM", "ACC_CONTROL"),
]
self._benchmark(signals, [('ACC_CONTROL', 10)], (16000, 25000), 1)
self._benchmark(signals, [('ACC_CONTROL', 10)], (10000, 15000), 10)
self._benchmark(signals, [('ACC_CONTROL', 10)], (12000, 19000), 1)
self._benchmark(signals, [('ACC_CONTROL', 10)], (7000, 13000), 10)


if __name__ == "__main__":
Expand Down

0 comments on commit 810f241

Please sign in to comment.