dallbit Prompt & Skill

Memory Consumption Optimizer

Analyzes code with excessive memory usage and optimizes it using streaming, chunking, or memory management techniques.

Prompt Template

The more specific your inputs, the higher the quality of the output.

{{current_usage}}
{{target_usage}}
{{source_code}}

You are a System Performance Engineer. Analyze the cause of excessive memory consumption (2.5GB vs target 200MB) in the provided code and suggest optimizations. ### Source Code const data = fs.readFileSync('large-data.json'); const result = process(data); ### Tasks 1. **Identify Memory Overhead**: Find sections where data is loaded all at once or where garbage collection (GC) is hindered. 2. **Apply Techniques**: Refactor code using memory-efficient methods such as Streaming, Chunking, or WeakRef usage. 3. **Comparative Analysis**: Explain the difference in memory usage before and after optimization and the expected stability gain. ### Output Format - Provide an analysis report along with the refactored code for improved memory efficiency. Example: Reducing memory usage by using `createReadStream` instead of reading a large file with `readFileSync`.