opendbc
opendbc copied to clipboard
can: cache DBC parsing to speed up car interface tests
Performance
Cuts test_car_interfaces.py runtime from ~127 s to ~57.19s (≈2.2× faster). The slowest test drops from ~11 s to ~1.66 s (that's 7x faster), this must meeting the target of ≤0.2 s avg and <1 s max per car.
Changes
- DBC caching: Added a class-level cache keyed by absolute file path so each DBC file is parsed only once per process. Subsequent CANParser instantiations reuse the cached instance.
- CANParser fast path: Early-return in CANParser.update when called with an empty frame list, avoiding needless buffer clearing.
Verification
Ran the test suite before and after the change:
pytest --durations=10 selfdrive/car/tests/test_car_interfaces.py