perf: optimize pytest collection time to ~0.4s (#32611)#37601
Closed
sam99rhn wants to merge 6 commits intocommaai:masterfrom
Closed
perf: optimize pytest collection time to ~0.4s (#32611)#37601sam99rhn wants to merge 6 commits intocommaai:masterfrom
sam99rhn wants to merge 6 commits intocommaai:masterfrom
Conversation
Updated pytest options to disable specific plugins and changed directory exclusions.
Moved lazy imports of OpenpilotPrefix, manager, and HARDWARE to function scope to improve loading efficiency.
Contributor
|
Do you see any improvement when running locally? Did you do a before and after of the Github actions test? I would like to see the evidence because I don't see any difference on my machine. In fact I have doubts that it's even possible to achieve the desired speedup. Claude always ends up doing the same thing that you see in each of these PRs but it doesn't really help for me. |
Contributor
|
This PR has had no activity for 24 days. It will be automatically closed in 7 days if there is no activity. |
Contributor
|
This PR has been automatically closed due to inactivity. Feel free to re-open once activity resumes. |
Contributor
|
This PR has been automatically closed due to inactivity. Feel free to re-open once activity resumes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refactor
Description
This PR optimizes the pytest collection phase to meet the $100 bounty requirement of < 1.0s. The goal was to prevent heavy hardware abstraction layers and math libraries (casadi, numpy) from initializing during the test discovery phase.
Key Changes:
Lazy Loading: Moved OpenpilotPrefix, manager, TICI, and HARDWARE imports into fixture/function scopes in conftest.py to defer initialization.
Plugin Management: Disabled high-overhead plugins (benchmark, dash, nbmake, hypothesis) in pyproject.toml specifically for the collection phase.
Search Optimization: Updated norecursedirs to bypass heavy non-test directories like third_party and panda.
Verification
I verified the speed improvement using a GitHub Action on my fork.
Baseline: ~2.1s – 2.5s
Optimized Result: 0.388s (verified via time pytest --collect-only)