Skip to content

Commit 18c1f08

Browse files
logesh45sshane
andauthored
can: cache DBC parsing to speed up car interface tests (#2888)
* can: cache DBC parsing to speed up car interface tests - Keep a class-level cache of parsed DBC files so each path is parsed once per process - Return early in CANParser.update when no frames arrive to avoid needless work - Cuts test_car_interfaces runtime significantly * can: refactor DBC caching to use explicit factory function * revert * simple cache dbc it's not at all used like a dataclass --------- Co-authored-by: Shane Smiskol <[email protected]>
1 parent 634922b commit 18c1f08

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

opendbc/can/dbc.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import re
22
import os
3-
from dataclasses import dataclass
43
from collections.abc import Callable
4+
from dataclasses import dataclass
5+
from functools import cache
56

67
from opendbc import DBC_PATH
78

@@ -73,14 +74,8 @@ class Val:
7374
VAL_SPLIT_RE = re.compile(r'["]+')
7475

7576

76-
@dataclass
77+
@cache
7778
class DBC:
78-
name: str
79-
msgs: dict[int, Msg]
80-
addr_to_msg: dict[int, Msg]
81-
name_to_msg: dict[str, Msg]
82-
vals: list[Val]
83-
8479
def __init__(self, name: str):
8580
dbc_path = name
8681
if not os.path.exists(dbc_path):

0 commit comments

Comments
 (0)