SUS03-BP03 Optimize areas of code that consume the most time or resources
This best practice was updated with new guidance on July 13th, 2023. |
Optimize your code that runs within different components of your architecture to minimize resource usage while maximizing performance.
Common anti-patterns:
-
You ignore optimizing your code for resource usage.
-
You usually respond to performance issues by increasing the resources.
-
Your code review and development process does not track performance changes.
Benefits of establishing this best practice: Using efficient code minimizes resource usage and improves performance.
Level of risk exposed if this best practice is not established: Medium
Implementation guidance
It is crucial to examine every functional area, including the code for a cloud architected application, to optimize its resource usage and performance. Continually monitor your workload’s performance in build environments and production and identify opportunities to improve code snippets that have particularly high resource usage. Adopt a regular review process to identify bugs or anti-patterns within your code that use resources inefficiently. Leverage simple and efficient algorithms that produce the same results for your use case.
Implementation steps
-
While developing your workloads, adopt an automated code review process to improve quality and identify bugs and anti-patterns.
-
As you run your workloads, monitor resources to identify components with high resource requirements per unit of work as targets for code reviews.
-
For code reviews, use a code profiler to identify the areas of code that use the most time or resources as targets for optimization.
-
Use the most efficient operating system and programming language for the workload. For details on energy efficient programming languages (including Rust), see Sustainability with Rust
. -
Replace computationally intensive algorithms with simpler and more efficient version that produce the same result.
-
Remove unnecessary code such as sorting and formatting.
Resources
Related documents:
Related videos: