SUS03-BP03 Optimize areas of code that consume the most time or resources
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
-
Use efficient programming language: Use an efficient operating system and programming language for the workload. For details on energy efficient programming languages (including Rust), see Sustainability with Rust
. -
Use an AI coding companion: Consider using an AI coding companion such as Amazon Q Developer
to efficiently write code. -
Automate code reviews: While developing your workloads, adopt an automated code review process to improve quality and identify bugs and anti-patterns.
-
Use a code profiler: Use a code profiler to identify the areas of code that use the most time or resources as targets for optimization.
-
Monitor and optimize: Use continuous monitoring resources to identify components with high resource requirements or suboptimal configuration.
-
Replace computationally intensive algorithms with simpler and more efficient version that produce the same result.
-
Remove unnecessary code such as sorting and formatting.
-
-
Use code refactoring or transformation: Explore the possibility of Amazon Q code transformation
for application maintenance and upgrades.
Resources
Related documents:
Related videos:
Related examples: