memory-optimization
/memory-optimization
Cut a program's memory footprint by fixing data layout, reusing allocations, and streaming input instead of buffering it whole. Use when a process is killed by the OOM killer, garbage collection dominates the profile, or heap growth tracks input size.
- Author
- Amey-Thakur ↗
- Repository
- AI-SKILLS ↗
- Licence
- MIT
- Last repository change
- 05.09.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Cut a program's memory footprint by fixing data layout, reusing allocations, and streaming input instead of buffering it whole. Use when a process is killed by the OOM killer, garbage collection dominates the profile, or heap growth tracks input size.
Original author description
Cut a program's memory footprint by fixing data layout, reusing allocations, and streaming input instead of buffering it whole. Use when a process is killed by the OOM killer, garbage collection dominates the profile, or heap growth tracks input size.
How it works
- Method
- Checks
- Boundaries
SKILL.md preview
--- name: memory-optimization description: Cut a program's memory footprint by fixing data layout, reusing allocations, and streaming input instead of buffering it whole. Use when a process is killed by the OOM killer, garbage collection dominates the profile, or heap growth tracks input size. --- # Memory optimization Memory is spent in three ways a CPU profile hides: how each object is laid out, how many you allocate, and how much you hold at once. A program can be fast and still get OOM-killed because it buffers a whole file it could have streamed. Cut footprint by attacking layout, allocation rate, and retention, in that order. ## Method 1. **Measure the heap before touching layout.** Get a real allocation profile: `pprof` for Go, `tracemalloc` or `memory_profiler` for Python, a heap snapshot in Chrome DevTools, `jmap`/`jcmd` for the JVM. Find which type owns the most live bytes and which call site allocates most. Optimize the top one, not a guess. 2. **Shrink the hot object's layout.** Reorder struct fields so same-size members sit together and padding collapses; a naive Go or C struct can waste near a third to alignment. Use a narrower type where the range allows (`int32` over `int64`), and in Python give hot classes `__slots__` to drop the per-instance `__dict__`. 3. **Store many-of-a-thing column-wise.** A million small objects each carry header and pointer overhead. A struct-of-arrays layout (parallel typed arrays, a NumPy array, an Arrow column) cuts per-element overhead to near zero and packs the working set into fewer cache lines. 4. **Pool and reuse instead of churning.** For short-lived objects allocated in a hot loop, reuse buffers: a `sync.Pool` in Go, a slice you reslice to `[:0]` and refill, a reused `bytearray`. Fewer allocations means fewer collections, and GC time often falls faster than the byte count. 5. **Stream instead of buffering the whole payload.** Reading a file or response into one string peaks at its full size; iterate line by line or in fixed chunks so peak memory is a window, not the total. Use generators, `io` readers, or a SAX-style parser rather than loading a full document into a DOM. 6. **Cap what you retain.** Bound caches and queues with an eviction policy (LRU with a max size) so retained memory has a ceiling. A cache with no bound is a slow leak that a heap profile eventually blames on the wrong code. ## Checks - Does peak resident memory stay flat as input grows, or track its size? - Did the dominant type in the heap profile actually shrink after the change? - Under load, has GC time or pause frequency dropped, not just live bytes? - Does every long-lived cache or buffer carry an explicit size bound? ## Boundaries This reduces intended footprint by design. Hunting an unbounded climb from unintended retention is memory-leaks; reading the profile that finds the offender is profiling-memory. Collector pause tuning past allocation rate belongs to gc-tuning.
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · Amey-Thakur/AI-SKILLS | 90 | MIT |
| drayline/rootnode-skills | 100 | Apache-2.0 |
| benchflow-ai/skillsbench | 100 | Apache-2.0 |
| andreibesleaga/gabbe | 90 | CC-BY-4.0 |
Database snapshot: 13.11.2026 · package version 58ef8c4ee054 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 90memory-leaks
Find the object that never gets freed by comparing heap snapshots and following retention paths. Use when a process grows in memory over time, gets OOM-killed, or slows under a garbage collector that keeps working harder. - 90profiling-memory
Attribute memory growth and allocation churn to the exact call sites that produce it using an allocation profiler. Use when a process grows without bound, spends too much time in garbage collection, or allocates far more than its working set explains. - 100memory-leak-debugging
Diagnoses and resolves memory leaks in JavaScript/Node.js applications. Use when a user reports high memory usage, OOM errors, or wants to capture, compare, or inspect heap snapshots with Chrome DevTools MCP memory tools. - 85Nim Memory Management
Use when nim's memory management including garbage collection strategies, manual memory control, destructors, move semantics, ref/ptr types, memory safety, and optimization techniques for performance-critical systems programming. - 90java-jvm-performance-and-gc
Use this skill when statically reviewing a proposed JVM garbage-collector or performance change — collector selection (G1, ZGC/Generational ZGC, Shenandoah, Parallel), allocation-pressure source patterns, heap-sizing/GC-flag configuration, and OOM/memory-leak triage. Trigger… - 100garbage-collection
This skill should be used when the user asks about "garbage collection rules", "entropy fighting", "documentation staleness", "dead code detection", "convention drift", "periodic checks", "auto-fix rules", or needs guidance on the Garbage Collection section of HARNESS.md.