-
Notifications
You must be signed in to change notification settings - Fork 22
pydantic ai benchmarking support #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Saurabh Misra <[email protected]>
Signed-off-by: Saurabh Misra <[email protected]>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
…items` by 670% in PR #574 (`easier-benchmark`) Here’s how you can optimize your code for **speed** and **memory** while maintaining return values, behavior, and comments. I focused on making `pytest_collection_modifyitems` faster by. - **Avoiding function calls/attribute checks inside tight loops:** Since ideally `get_closest_marker` existence is consistent across items, fetch it once per item and cache the lookup. - **Reducing repeated work:** Move more work (e.g. creation of the skip marker) outside the inner loop. ### Changes and Optimizations. - **Cache Attribute**: `getattr(item, "get_closest_marker", None)` is used to avoid repeated `hasattr` checks or repeated attribute lookups. - **Reuse Marker Instance**: `skip_marker` is created once, not in every loop iteration. - **Skip on missing attribute** instead of raising. **This will speed up the loop by:** - Reducing per-item attribute lookup - Reducing decorator construction - Reducing function calls on items which don’t have `get_closest_marker` (if any) --- Let me know if you want further or different optimizations!
⚡️ Codeflash found optimizations for this PR📄 670% (6.70x) speedup for
|
PR Type
Enhancement
Description
Add debugging prints in trace wrapper
Introduce frozen
BenchmarkKeydataclassExtend module path traversal logic
Refine pytest marker handling and skip logic
Diagram Walkthrough
File Walkthrough
codeflash_trace.py
Add debug prints in trace wrappercodeflash/benchmarking/codeflash_trace.py
plugin.py
Introduce BenchmarkKey and marker handlingcodeflash/benchmarking/plugin/plugin.py
BenchmarkKeydataclass with__str__.traverse_up=Trueto module name resolution.code_utils.py
Enhance module path traversal logiccodeflash/code_utils/code_utils.py
traverse_upparameter to fallback relative path logic.pytest_new_process_discovery.py
Register benchmark marker in discovery plugincodeflash/discovery/pytest_new_process_discovery.py
pytest_configureto registerbenchmarkmarker.optimizer.py
Refactor run_benchmarks flowcodeflash/optimization/optimizer.py
console.rule()before benchmarks.