Memory Usage Optimizer
This loop automatically analyzes and optimizes the codebase to reduce memory consumption. It iteratively identifies high-memory components, applies targeted optimizations (e.g., caching, lazy loading, data structure improvements), and validates improvements using a memory benchmark until the desired target is achieved or the maximum iterations are reached.
Goal
Lower memory usage
How to Run
Initiate the loop by running the kickoff prompt in your coding environment. The agent will autonomously execute workflow steps, run memory checks after each iteration, and stop once the target is met or the iteration limit is reached.
- 01
Prepare Environment
Ensure your project has a working memory benchmark script or command that outputs current memory usage metrics.
- 02
Run Kickoff Prompt
Paste the kickoff prompt into your coding agent interface (Cursor, Claude Code, etc.) to start the optimization loop.
- 03
Monitor Progress
The agent will self-pace through workflow steps, running the check command after each action until the exit condition is met.
Workflow Steps
- 01
Analyze current memory usage using the memory benchmark command to establish a baseline.
Record initial memory usage metrics for comparison.
- 02
Identify top memory-consuming modules or functions via profiling or log analysis.
List components contributing most to memory overhead.
- 03
Apply targeted optimizations such as caching strategy improvements, lazy loading, or replacing heavy data structures.
Ensure changes are applied safely without breaking functionality.
- 04
Re-run the memory benchmark to measure improvement.
Compare new memory usage against previous results and target threshold.
- 05
If target not met and iterations remain, return to step 2 for further optimization.
Loop until exit condition or max iterations reached.
Kickoff Prompt
Start the "Memory Usage Optimizer" loop. Goal: Lower memory usage Max iterations: 10 Between iterations run: memory benchmark Exit when: Memory usage meets or falls below the target threshold specified in the kickoff prompt Start the Memory Usage Optimizer loop. First, run the 'memory benchmark' command to assess current memory usage. Then, identify the most memory-intensive parts of the codebase and apply one optimization (e.g., caching, lazy loading, efficient data structures). Re-run the benchmark to check progress. Continue this cycle up to 10 times or until memory usage meets the target of [X MB/percentage reduction]. Self-pace this loop. After each iteration, run `memory benchmark` and evaluate the output, and only continue if the exit condition is not met (Memory usage meets or falls below the target threshold specified in the kickoff prompt). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.
Guardrails
hardcoded- ·Do not modify core system or runtime libraries unless explicitly required and safe to do so.
- ·Always create backups or use version control before applying memory optimizations.
- ·Validate each optimization step to ensure it does not introduce functional regressions.
- ·Prioritize optimizations that maintain or improve code readability and maintainability.
Flow Diagram
Related loops — Performance
Performance
Bundle Size Reducer
Iteratively reduces JavaScript bundle size by analyzing dependencies, identifying large modules, and applying targeted optimizations until a specified size target is met.
Performance
Frontend Speed Optimizer
Automatically improves frontend page speed by iteratively analyzing Lighthouse reports and applying targeted optimizations. This loop runs until your target Lighthouse performance score is achieved.
Performance
Slow Endpoint Hunter
This loop identifies and optimizes slow API endpoints by continuously benchmarking, analyzing performance bottlenecks, and applying targeted improvements until response times meet predefined budgets.