Memory Optimization
Optimize Python code for reduced memory usage and improved memory efficiency. Use when asked to reduce memory footprint, fix memory leaks, optimize data structures for memory, handle large datasets efficiently, or diagnose memory issues. Covers object sizing, generator patterns, efficient data structures, and memory profiling strategies.
Install
npx skills add UCSB-NLP-Chang/Skill-Usage --skill memory-optimizationgit clone --depth 1 https://github.com/UCSB-NLP-Chang/Skill-Usage.git /tmp/Skill-Usage
mkdir -p ~/.claude/skills
cp -r /tmp/Skill-Usage/tasks/parallel-tfidf-search/environment/skills/memory-optimization ~/.claude/skills/memory-optimizationPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# Memory Optimization Skill
Transform Python code to minimize memory usage while maintaining functionality.
## Workflow
1. **Profile** to identify memory bottlenecks (largest allocations, leak patterns)
2. **Analyze** data structures and object lifecycles
3. **Select** optimization strategies based on access patterns
4. **Transform** code with memory-efficient alternatives
5. **Verify** memory reduction without correctness loss
## Memory Optimization Decision Tree
```
What's consuming memory?
Large collections:
├── List of objects → __slots__, namedtuple, or dataclass(slots=True)
├── List built all at once → Generator/iterator pattern
├── Storing strings → String interning, categorical encoding
└── Numeric data → NumPy arrays instead of lists
Data processing:
├── Loading full file → Chunked reading, memory-mapped files
├── Intermediate copies → In-place operations, views
├── Keeping processed data → Process-and-discard pattern
└── DataFrame operations → Downcast dtypes, sparse arrays
Object lifecycle:
├── Objects never freed → Check circular refs, use weakref
├── Cache growing unbounded → LRU cache with maxsize
├── Global accumulation → Explicit cleanup, context managers
└── Large temporary objects → Delete explicitly, gc.collect()
```
## Transformation Patterns
### Pattern 1: Class to __slots__
Reduces per-instance memory by 40-60%:
**Before:**
```python
class Point:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
```Details
- Skill name
memory-optimization- Repository
- UCSB-NLP-Chang/Skill-Usage
- Path
tasks/parallel-tfidf-search/environment/skills/memory-optimization/SKILL.md- Repo updated
- 8 April 2026
FAQ
What does the Memory Optimization skill do?
Optimize Python code for reduced memory usage and improved memory efficiency. Use when asked to reduce memory footprint, fix memory leaks, optimize data structures for memory, handle large datasets efficiently, or diagnose memory issues. Covers object sizing, generator patterns, efficient data structures, and memory profiling strategies.
How do I install the Memory Optimization skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add UCSB-NLP-Chang/Skill-Usage --skill memory-optimization. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Memory Optimization popular?
It lives in UCSB-NLP-Chang/Skill-Usage, which has 49 GitHub stars and 5 forks.
Related skills
Pubchem Database
49UCSB-NLP-Chang/Skill-Usage
Query PubChem via PUG-REST API/PubChemPy (110M+ compounds). Search by name/CID/SMILES, retrieve properties, similarity/substructure searches, bioactivity, for cheminformatics.
Pymatgen
49UCSB-NLP-Chang/Skill-Usage
Materials science toolkit. Crystal structures (CIF, POSCAR), phase diagrams, band structure, DOS, Materials Project integration, format conversion, for computational materials science.
Rdkit
49UCSB-NLP-Chang/Skill-Usage
Cheminformatics toolkit for fine-grained molecular control. SMILES/SDF parsing, descriptors (MW, LogP, TPSA), fingerprints, substructure search, 2D/3D generation, similarity, reactions. For standard workflows with simpler interface, use datamol (wrapper around RDKit). Use rdkit for advanced control, custom sanitization, specialized algorithms.
Parallel Processing
49UCSB-NLP-Chang/Skill-Usage
Parallel processing with joblib for grid search and batch computations. Use when speeding up computationally intensive tasks across multiple CPU cores.
Lean4 Memories
49UCSB-NLP-Chang/Skill-Usage
This skill should be used when working on Lean 4 formalization projects to maintain persistent memory of successful proof patterns, failed approaches, project conventions, and user preferences across sessions using MCP memory server integration
Pcap Triage Tshark
49UCSB-NLP-Chang/Skill-Usage
Fast workflow to inspect PCAPs and extract protocol-level details using tshark
Browse the most popular Claude skills, all productivity & notes skills, or write your own with the skills generator.