From 810f241ffcd7633dce32feeec6f996080399b6d9 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Sun, 2 Apr 2023 22:45:51 +0800 Subject: [PATCH] CANParser: improve cython performance (#802) * 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 --- can/parser_pyx.pyx | 16 ++++++++++++---- can/tests/test_parser.py | 8 ++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/can/parser_pyx.pyx b/can/parser_pyx.pyx index 9867305efa..97b9562826 100644 --- a/can/parser_pyx.pyx +++ b/can/parser_pyx.pyx @@ -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] @@ -111,22 +111,30 @@ cdef class CANParser: # Cast char * directly to unicode cv_name = 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: diff --git a/can/tests/test_parser.py b/can/tests/test_parser.py index fc60b8d1e7..1978b5440a 100755 --- a/can/tests/test_parser.py +++ b/can/tests/test_parser.py @@ -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 = [ @@ -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__":