Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️ Speed up method `ModelToComponentFactory._create_async_job_status_…
…mapping` by 8% in PR #45178 (`async-job/cdk-release`) Certainly! Here is the rewritten Python program optimized for better performance. ### Optimization Changes. 1. **Removed Redundant Imports:** Only essential imports are retained to improve the program's load time. 2. **Consolidated Enum Definitions:** Avoided redundancy and moved the `AsyncJobStatus` Enum definition to the top. 3. **Initialization Improvements:** - Mapped status directly in a dictionary for faster lookup instead of using the `match` statement. - Combined the `if status in api_status_to_cdk_status` validation to the main loop to avoid additional checks. 4. **Eliminated Redundant String Checks:** For checking CDK status, utilized the loop over predefined list `["running", "completed", "failed", "timeout"]`. 5. **Refactored `_get_async_job_status` for Direct Dictionary Access:** This avoids the overhead of match/case or if-else checks, speeding up decision-making. These optimizations reduce the overall complexity and execution time, particularly for the method generating mappings and querying job statuses.
- Loading branch information