⚡️ Speed up method OnCallPagingApi.resolve_on_call_page by 5%
#12
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.
📄 5% (0.05x) speedup for
OnCallPagingApi.resolve_on_call_pageinsrc/datadog_api_client/v2/api/on_call_paging_api.py⏱️ Runtime :
3.72 milliseconds→3.53 milliseconds(best of66runs)📝 Explanation and details
The optimized code achieves a 5% speedup through two key micro-optimizations that reduce function call overhead:
Key Optimizations:
Direct parameter passing in
resolve_on_call_page: Eliminated the intermediate dictionary creation (kwargs: Dict[str, Any] = {}andkwargs["page_id"] = page_id) and passed the parameter directly aspage_id=page_id. This removes two variable assignments and dictionary operations.Import reorganization: Separated the
ApiClientimport from theEndpointimport to potentially reduce import resolution overhead, though this has minimal impact.Why This Works:
call_with_http_info, but the remaining 4.6% was overhead from dictionary operationskwargsdictionary creation and assignment, we remove Python's dictionary allocation and key assignment operations**kwargsunpacking, especially for single parametersTest Case Performance:
The optimizations show consistent improvements across different scenarios:
This optimization is particularly effective for high-frequency API calls where every microsecond of overhead reduction compounds significantly.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-OnCallPagingApi.resolve_on_call_page-mgc5uwhhand push.