-
Notifications
You must be signed in to change notification settings - Fork 22
Benchmark Fixture fixes #586
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
PR Reviewer Guide 🔍(Review updated until commit 41d314d)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 41d314d Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit d3a0035
Suggestions up to commit ad90c2d
|
|
Persistent review updated to latest commit d3a0035 |
…(`benchmark-fixture-fix`)
Here is an optimized version, **rewritten for maximum runtime performance**.
- **Major hotspots** (from the profiler) are:
- `get_function_alias` and `get_unique_test_name` – called thousands of times, simple string ops.
- Many calls to `get_function_alias` **duplicate input** in many places.
- Many repeated lookups (`func.get("key")`).
- `textwrap.indent` and especially `textwrap.dedent` called many times with the same strings.
- **Optimization strategies:**
- **Cache** results of `get_function_alias` and `get_unique_test_name` per argument tuple (using `functools.lru_cache`).
- **Pre-dedent** test templates once at function scope, not in loop.
- **Minimize string concatenation**, and loop variable lookups.
- Use **list building** + `''.join()` for string results where appropriate.
- Avoid repeated `str.format`/f-string reinterpretation in tight loops: compose test bodies fully with known variables, not dynamic format.
- Inline/copy critical logic to avoid redundant function calls per-loop where possible (without changing output).
- Inline simple get-alias pattern for unique test name.
- **Batch key access** from `func` via local variables, and give fast locals in all loops.
---
---
**Key optimizations explained:**
- `@lru_cache` for `get_function_alias` and `get_unique_test_name`: avoids recomputation for repeated arguments, which are very frequent.
- Templates are dedented **once** at module load, dramatically cutting cost of repeated dedentation per test case.
- All `func.get("key")` inside tight loops are replaced by direct `func["key"]` to avoid re-parsing and make local lookups faster.
- String concatenations are gathered in lists and joined at the end for efficiency (instead of `+=`).
- All template string field subs are consolidated to minimize calls to slow formatting/f-strings inside loops.
- Minimizes repeated lookups and attribute access by using local variables for everything repeatedly accessed in loops.
This should result in very significant **runtime reduction** for large numbers of test generation, as all major hotspots are addressed. Output remains identical to the original.
⚡️ Codeflash found optimizations for this PR📄 36% (0.36x) speedup for
|
78fa5b4 to
b478f10
Compare
|
Persistent review updated to latest commit 41d314d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM

User description
Update plugin.py
PR Type
Enhancement, Tests, Bug fix, Other
Description
Add
codeflash-benchmarkplugin packaging and versioningEnhance pytest hooks and benchmark fixture fallback logic
Generate unique replay test names and update test expectations
Support aliased import detection in unit test discovery
File Walkthrough