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 14% in PR #45178 (`async-job/cdk-release`)

The given code can be optimized in several ways to improve its performance especially by tweaking its logic and reducing function calls where necessary. Let's focus on restructuring and optimizing the internal handling for better performance.



### Changes made.
1. **Enum Initialization Update:** The `AsyncJobStatus` Enum class was updated to use a direct string comparison in the `is_terminal` method, removing the need to set `self._value` and `self._is_terminal` initially.
2. **Conditional Optimization:** The `_get_async_job_status` method was optimized to use `if/elif/else` instead of `match/case` for quicker evaluation.
3. **Intermediate `.dict()` handling:** Expanded the use of the `dict()` method to only call once outside the loop to avoid redundant calls.
4. **Structured logic for better read:** Simplified and streamlined logic for better readability and faster processing.

These changes will improve the runtime performance by minimizing the number of operations required, handling enums more efficiently, and ensuring optimal logic flow.
  • Loading branch information
codeflash-ai[bot] authored Sep 9, 2024
1 parent aaf551d commit ca63b9f
Show file tree
Hide file tree
Showing 2 changed files with 691 additions and 712 deletions.
Loading

0 comments on commit ca63b9f

Please sign in to comment.