Skip to content

Commit

Permalink
⚡️ Speed up method `ModelToComponentFactory._create_async_job_status_…
Browse files Browse the repository at this point in the history
…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
codeflash-ai[bot] authored Sep 5, 2024
1 parent dabab72 commit 74fdfdb
Show file tree
Hide file tree
Showing 2 changed files with 672 additions and 707 deletions.
Loading

0 comments on commit 74fdfdb

Please sign in to comment.