⚡️ Speed up method CloudCostManagementApi.get_custom_costs_file by 23%
#2
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.
📄 23% (0.23x) speedup for
CloudCostManagementApi.get_custom_costs_fileinsrc/datadog_api_client/v2/api/cloud_cost_management_api.py⏱️ Runtime :
299 microseconds→243 microseconds(best of123runs)📝 Explanation and details
The optimization applies two key performance improvements that eliminate unnecessary dictionary operations:
1. Fast-path optimization in
Endpoint.call_with_http_info:list(kwargs.keys())and multiple dictionary lookups for single-parameter endpoints2. Direct parameter passing in
get_custom_costs_file:kwargsdictionary and then calling**kwargs, the method now directly passesfile_id=file_idkwargs: Dict[str, Any] = {}), key assignment (kwargs["file_id"] = file_id), and unpacking (**kwargs) operationsWhy this leads to speedup:
get_custom_costs_filewith justfile_id)Test case benefits:
The annotated tests show consistent 20-30% improvements across most scenarios, with the largest gains (42-53%) in cases involving single-parameter calls or repeated operations, which directly benefit from the reduced dictionary overhead.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
🔎 Concolic Coverage Tests and Runtime
To edit these changes
git checkout codeflash/optimize-CloudCostManagementApi.get_custom_costs_file-mgau67lmand push.