Optimize test_car_interfaces: cache strategies, Kalman gain, and early return #3016
+30
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR optimizes
test_car_interfacesto achieve significant speedup:Changes
Cache Hypothesis strategy objects - Created
@cachedecorated function_get_params_strategy()to avoid expensive recreation of strategy objects on every test invocationReduce search space - Added
max_size=5limits tost.dictionariesandst.liststo reduce the hypothesis search spaceCache Kalman gain computation - Added
_get_kalman_gain_cached()function to cache the expensive 100-iteration matrix computation that's always called with identical parametersEarly return for empty updates - Added early return in
CANParser.update()when called with empty strings to avoid unnecessary dictionary clearing operationsPerformance Impact
Related
Part of the effort to resolve commaai/openpilot#32536 - Speedup test_car_interfaces to achieve ≤0.2s avg and <1s max per car test.
This PR works in conjunction with https://github.com/commaai/openpilot/pull/[PR_NUMBER] which reduces MAX_EXAMPLES and updates the opendbc submodule reference.