Skip to content

perf: optimize get_interface_attr collection overhead#3367

Open
brianescutia wants to merge 1 commit intocommaai:masterfrom
brianescutia:brian/get-interface-attr-optimization
Open

perf: optimize get_interface_attr collection overhead#3367
brianescutia wants to merge 1 commit intocommaai:masterfrom
brianescutia:brian/get-interface-attr-optimization

Conversation

@brianescutia
Copy link
Copy Markdown

Summary

Optimizes get_interface_attr() in opendbc/car/interfaces.py to reduce pytest collection overhead.

Changes:

  • iterate over canonical BRANDS instead of walking BASEDIR
  • cache brand directory discovery
  • cache interface attribute lookups
  • avoid failed dynamic imports from non-brand directories

Motivation

While investigating #1184, I profiled opendbc/car/tests/ collection and found time spent in get_interface_attr() from filesystem walking and dynamic imports.

This change keeps the same public return shape while returning a fresh dict from cached tuple data to avoid cache poisoning if callers mutate the result.

Benchmarks

Before:

uv run pytest --cache-clear --co opendbc/car/tests/
# 763 tests collected in ~1.13s

After:

uv run pytest --cache-clear --co opendbc/car/tests/
# 763 tests collected in ~0.74s

Validation

uv run pytest opendbc/car/tests/test_car_interfaces.py -x
# 246 passed

uv run pytest opendbc/car/tests/test_fw_fingerprint.py -x
# 14 passed

uv run pytest opendbc/car/tests/test_docs.py -x
# 6 passed

uv run pytest opendbc/car/tests/test_platform_configs.py -x
# 1 passed

./test.sh
# All good! Finished lint and test

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Car behavior report

Replays driving segments through this PR and compares the behavior to master.
Please review any changes carefully to ensure they are expected.

✅ No changes detected

@github-actions github-actions Bot added the car related to opendbc/car/ label May 1, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing to opendbc! In order for us to review your PR as quickly as possible, check the following:

  • Convert your PR to a draft unless it's ready to review
  • Read the contributing docs
  • Before marking as "ready for review", ensure:
    • the goal is clearly stated in the description
    • all the tests are passing
    • include a route or your device' dongle ID if relevant

@brianescutia
Copy link
Copy Markdown
Author

tests / test models (1) failed again due to an unavailable Rivian route:

c70d59e4150956fc/0000006e--48bfbfda01

This appears unrelated to this PR since ./test.sh, car diff, safety checks, and the other model shards passed, and the car behavior report shows no changes detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

car related to opendbc/car/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant