mohitmishra786/low-level-dev-skills

resource-optimization-lowend

Resource optimization skill for constrained embedded targets.

View source

How to use

  1. Copy the installation command and review the source package before installing it in your own agent environment.
  2. Check the source document for required tools, credentials and supported hosts.
  3. Describe your input and desired deliverable; review the output against the source material.
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill resource-optimization-lowend

Before you start

  • Installation does not include a model subscription, API allowance or permission to access your files.
  • Repository stars and installation counts describe activity, not an independent quality or security test.
Original skill document

Rendered from the source repository. Headings, examples, code, tables, links, and referenced images are preserved.

Resource Optimization (Low-End Systems)

Purpose

Guide agents through flash and RAM optimization on constrained devices: compiler size flags, linker map analysis, stack usage measurement, dead code elimination, and size-vs-speed tradeoffs — for bare-metal and small RTOS images.

When to Use

  • Firmware exceeds flash budget
  • Stack overflow in production only
  • Choosing -Os vs -O2 on MCU
  • Finding unexpected .rodata or .bss growth

Workflow

1. Size measurement toolchain

bash
arm-none-eabi-size -A firmware.elf
arm-none-eabi-objdump -h firmware.elf
nm --size-sort -S firmware.elf | tail -20

2. Linker map file

ld
/* linker.ld */
OUTPUT_FORMAT("elf32-littlearm")
ENTRY(Reset_Handler)

SECTIONS
{
  /* ... */
}

/* Generate map */
/* gcc ... -Wl,-Map=firmware.map */
bash
grep -E '\.text|\.rodata|\.data|\.bss' firmware.map | head

Identify largest symbols and unexpected library pull-in.

3. Compiler flags

FlagEffect
-OsSize-first optimization
-ffunction-sections -fdata-sectionsPer-symbol sections
-Wl,--gc-sectionsDrop unused sections
-fltoCross-TU dead code elimination
-specs=nano.specsSmaller newlib (GCC ARM)
makefile
CFLAGS += -Os -ffunction-sections -fdata-sections
LDFLAGS += -Wl,--gc-sections -Wl,--print-memory-usage

4. Stack analysis

bash
# Static (if built with -fstack-usage)
find . -name '*.su' -exec cat {} \;

# Linker stack symbol
grep _estack firmware.map

Runtime: fill stack with pattern (0xDEADBEEF), run tests, scan high-water mark. FreeRTOS: uxTaskGetStackHighWaterMark.

5. RAM categories

SectionTactic
.bssShrink buffers; pool allocators
.dataMove const to flash (const → .rodata)
HeapAvoid malloc; fixed pools
StackReduce nesting; smaller ISR stacks

6. Size vs speed decision

Hot path in ISR or 1 kHz loop?
├── Yes → -O2 for that file (#pragma GCC optimize)
└── No  → -Os globally

7. Agent usage

/resource-optimization-lowend Find top 10 flash consumers in firmware.map and suggest -gc-sections fixes

Common Problems

SymptomCauseFix
printf pulls 20+ KBFull newlib printf_write retarget; tiny printf
--gc-sections broke IRQSection collectedKEEP() in linker script
Stack overflow lateDeep call + IRQ nestMeasure HW stack; increase _estack
RAM zero but big ELF.data not loadedCheck VMA/LMA
LTO link failMixed compiler versionsSame GCC for all objects

Related Skills

  • skills/embedded/linker-scripts — MEMORY/Sections layout
  • skills/baremetal/baremetal-startup — stack symbol
  • skills/baremetal/low-power-embedded — RAM retention
  • skills/compilers/gcc — optimization flags
  • skills/rust/rust-no-std — embedded Rust size patterns

Related by task

from this repository

More skills

All skills
mohitmishra786
Community

core-dumps

Core dump analysis skill for production crash triage. Use when loading core files in GDB or LLDB, enabling core dump generation on Linux/macOS, mapping symbols with debuginfo or debuginfod, or extracting backtraces from crashes without re-running the program. Activates on queries about core files, ulimit, coredumpctl, debuginfod, crash triage, or analyzing segfaults from production binaries.

installs
2
GitHub stars
267
Updated
Jun 27
mohitmishra786
Community

custom-allocators

Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator, GlobalAlloc, or fragmentation.

installs
2
GitHub stars
267
Updated
Jun 27
mohitmishra786
Community

ebpf

eBPF skill for Linux observability and networking. Use when writing eBPF programs with libbpf or bpftrace, attaching kprobes/tracepoints/XDP hooks, debugging verifier errors, working with eBPF maps, or achieving CO-RE portability across kernel versions. Activates on queries about eBPF, bpftool, bpftrace, XDP programs, libbpf, verifier errors, eBPF maps, or kernel tracing with BPF.

installs
2
GitHub stars
267
Updated
Jun 27
mohitmishra786
Community

flamegraphs

Flamegraph generation and interpretation skill. Use when converting perf, Valgrind Callgrind, or other profiler output into SVG flamegraphs using Brendan Gregg's FlameGraph tools, or when reading flamegraphs to identify performance bottlenecks. Activates on queries about flamegraphs, stackcollapse, flamegraph.svg, identifying hot frames, wide vs tall frames, or performance visualisation.

installs
2
GitHub stars
267
Updated
Jun 27