⚡️ Speed up method AgentlessScanningApi.delete_azure_scan_options by 44%
#1
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.
📄 44% (0.44x) speedup for
AgentlessScanningApi.delete_azure_scan_optionsinsrc/datadog_api_client/v2/api/agentless_scanning_api.py⏱️ Runtime :
3.61 milliseconds→2.50 milliseconds(best of105runs)📝 Explanation and details
The optimization eliminates unnecessary dictionary creation and unpacking in the
delete_azure_scan_optionsmethod.Key Change: The original code creates an empty dictionary (
kwargs: Dict[str, Any] = {}), assigns the parameter to it (kwargs["subscription_id"] = subscription_id), then unpacks it when calling the endpoint (**kwargs). The optimized version passes the parameter directly as a keyword argument (subscription_id=subscription_id).Why This is Faster:
__setitem__operation on the dictionary**kwargsunpackingPerformance Impact: The line profiler shows the optimization removes two expensive operations (7.2% and 8% of total time) that were pure overhead. The test results demonstrate consistent speedups across all scenarios:
This optimization is particularly effective for high-frequency API calls where the method is invoked thousands of times, as shown by the substantial improvements in the large-scale test cases.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
🔎 Concolic Coverage Tests and Runtime
To edit these changes
git checkout codeflash/optimize-AgentlessScanningApi.delete_azure_scan_options-mgam5n81and push.