GitLab Well Architected
Cookbook navigation
Prompts / Optimize Algorithm Performance

Optimize Algorithm Performance

Code QualityDeveloperOptimizationPerformanceCreateBeginner

Improve algorithmic efficiency while maintaining correctness. Optimize hot paths for performance gains.

For GitLab Duo

prompt

Optimize this algorithm:

[PASTE CODE]

Goals:
1. Improve time complexity
2. Reduce memory usage
3. Maintain correctness
4. Keep code readable

Use the prompt

Include representative input sizes and the result the algorithm must preserve. Measure the proposed implementation against the current one rather than relying on a complexity claim alone.