codesize
Skill1 starsChanged 7 days agoMITView on GitHub
MicroTech ESP32-S3/ESP32-P4 firmware code size analysis from the ESP-IDF linker map, ELF, build archives, and saved build snapshots. Use when identifying large libraries, objects, or symbols, comparing firmware builds for size regressions, checking Flash or internal RAM growth, or producing code size optimization guidance for this project.
In this repository12 other files it gives its agents.
- AGENTS.mdAGENTS.md
- aesthetic-reviewSkill
- app-developmentSkill
- design-contractSkill
- device-operationsSkill
- esp32Skill
- lvgl-integrationSkill
- lvgl-ui-layoutSkill
- motion-interactionSkill
- ui-reviewSkill
- ux-heuristicsSkill
- visual-designSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 31
Run the wrapper from the repository root:
- Very specific: line 59
When estimating LVGL widget savings, check the default theme: in LVGL 9, lv_theme_default.c references every enabled widget class, so …
- Very specific: line 74
Use the map report for bytes that are actually linked into the application.
- Very specific: line 100
Use --budget <json> to report budget violations without failing by default.
- Very specific: line 118
Use --fail-on-budget to return a non-zero exit code when a budget is exceeded.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MicroTech Firmware Code Size
This skill analyzes a MicroTech firmware build for either the ESP32-S3 (Xtensa)
or ESP32-P4 (RISC-V) target. It reports image storage, internal RAM, PSRAM, and
RTC memory from the linker map, attributes bytes to libraries, objects, and
input sections, and compares two builds through normalized map JSON. Read the
active target from build/project_description.json; do not assume Xtensa.
Inputs
- Application map:
build/microtech.map - Application ELF:
build/microtech.elf(used bypackage-size; map analysis reads the map) - Application binary:
build/microtech.bin - Build metadata:
build/project_description.json - Application archives:
build/esp-idf/**/*.a - Toolchain size command: the
*-sizematching the build target (xtensa-esp32s3-elf-sizeorriscv32-esp-elf-size), located throughbuild/project_description.json(monitor_toolprefix) or~/.espressif/tools - Saved comparison input: any build directory or map file produced by this project
The map file and ELF must come from the same build.
Entry Point
Run the wrapper from the repository root:
python3 .agents/skills/codesize/codesize.py <subcommand>Supported subcommands:
analyze-current: analyzebuild/microtech.mapanalyze-archives: run the toolchainsize -tover all application archivescompare-builds: compare two build directories or map filespackage-size: summarize built package artifacts
Current Map
python3 .agents/skills/codesize/codesize.py analyze-current --top 30
python3 .agents/skills/codesize/codesize.py analyze-current --group-by domain
python3 .agents/skills/codesize/codesize.py analyze-current --group-by object --top 50
python3 .agents/skills/codesize/codesize.py analyze-current --show-symbols--group-by library is the default. The report includes the largest libraries
and input sections, plus Flash Load share and the MicroTech domain breakdown.
--group-by object ranks object files, and --group-by domain aggregates the
engineering domains. --map selects another map file, and --build-dir
selects another ESP-IDF build directory.
When estimating LVGL widget savings, check the default theme: in LVGL 9,
lv_theme_default.c references every enabled widget class, so --gc-sections
retains objects such as lv_scale.c.obj even when application code never calls
the widget. Disabling the widget Kconfig or replacing the default theme is
required; a build with all widget options enabled cannot rely on link-time
garbage collection alone.
Archive Sizes
python3 .agents/skills/codesize/codesize.py analyze-archives --top 30This measures every archive under build/esp-idf/ with the Xtensa size tool.
Archive totals describe archive contents; they are not image contribution.
Use the map report for bytes that are actually linked into the application.
LVGL demo/example objects can dominate archive totals while being discarded by
--gc-sections; never use archive rankings alone to estimate app image growth.
Build Comparison
Save the current map before rebuilding, then compare:
cp build/microtech.map /tmp/microtech-before.map
# rebuild
python3 .agents/skills/codesize/codesize.py compare-builds \
--before /tmp/microtech-before.map \
--after build/microtech.map \
--object-diff \
--report-dir--before and --after accept a map file or a build directory containing the
application map. --report-dir writes Markdown and JSON under build/codesize/
unless a directory is supplied; --output can be used at the same time. Both
inputs may have the same application map basename. --symbol-diff includes
input-section-level deltas (the map parser uses input sections as its symbol
unit, not ELF symbol-table entries) and normalizes every symbol; it is slower
than the default library and object view.
Use --budget <json> to report budget violations without failing by default.
Budget values are bytes and describe allowed positive growth; negative values
are allowed for code removal. The supported shape is:
{
"max_flash_growth": 4096,
"max_ram_growth": 1024,
"max_psram_growth": 0,
"libraries": {
"libfreetype.a": {"max_flash_growth": 512, "max_ram_growth": 0}
},
"domains": {
"ui/graphics": {"max_flash_growth": 2048, "max_ram_growth": 512}
}
}Use --fail-on-budget to return a non-zero exit code when a budget is exceeded.
New libraries and their domains are included in library and domain budget
checks. --fail-on-growth <percent> is available when a total Flash percentage
limit is more appropriate than byte budgets.
Package Sizes
python3 .agents/skills/codesize/codesize.py package-size
python3 .agents/skills/codesize/codesize.py package-size \
--before /path/to/older-build \
--after /path/to/newer-buildThe report covers the application binary, ELF, map, bootloader binary, partition
table binary, OTA data, the final generated resource image, and release zip
files present in the directory. The resources metric is the final res.bin
image; temporary staging trees such as .res.bin.tmp are excluded. The
Partition Headroom table compares app_bin with each OTA app slot and the
resource image with the res data partition.
Accounting Model
The map report uses the linker output sections produced by the ESP-IDF linker scripts:
| Bucket | Linker sections | Flash Load | Internal RAM |
.text | .flash.text | yes | no |
.iram_text | .iram0.text, .iram0.vectors | yes | yes |
.rtc_text | .rtc.text, .rtc.force_fast, .rtc.force_slow | yes | yes |
.rodata | .flash.rodata, .flash.appdesc, .flash.tdata | yes | no |
.data | .dram0.data, .rtc.data, .iram0.data | yes | yes |
.bss | .dram0.bss, .rtc.bss, .rtc_noinit, .iram0.bss, .noinit.* | no | yes |
.psram_bss | .ext_ram.bss, .ext_ram_noinit | no | no (PSRAM) |
.psram_data | .ext_ram.data | no | no (PSRAM) |
.reserved_ram | .rtc_reserved | no | yes |
.rodata_noload | .flash.rodata_noload | no | no |
The output-section alignment placeholders .dram0.dummy, .ext_ram.dummy,
and .flash_rodata_dummy, plus the .iram0.text_end, .noinit, and
.dram0.heap_start markers, are excluded from runtime totals. .rodata_noload
is accounted separately and is not part of Flash Load. NOLOAD/Reserved in the
Markdown overview overlaps Internal RAM and PSRAM; it is not additional memory.
Library, object, and domain tables use input-section attribution. Input
.rodata.* sections placed inside .flash.text remain .rodata in those
tables. The linker merges mergeable .rodata.str* input sections into larger
literal pools; the map records the first section with its total size and a
size before relaxing value. The parser attributes only that first section's
pre-merge size to its archive and reports the remainder as [merged literals]
in the shared domain. The JSON summary exposes attributed_bytes,
merged_literals, alignment_fill, and unattributed; unattributed is
alignment filler not assigned to a library. COMMON input rows and input
sections whose names contain dummy are attributed normally.
Verification
Cross-check the map report against ESP-IDF:
idf.py size --format json2For a matching map and ELF, the map report Flash Load equals the total_size
field, and Internal RAM equals the sum of the DIRAM, RTC FAST, and
RTC SLOW used bytes. A mismatch usually means the map and ELF are from
different builds, but can also indicate a parser accounting defect; confirm
both artifacts and the parser version before using the result.
Output
- Default format: Markdown.
- JSON is the normalization format for map-to-map comparison.
- Map JSON contains
schema_version,tool_version,project,target,generated_at,architecture,summary,libraries,domains,objects, andtop_symbols;summaryalso containsattributed_bytes,merged_literals,alignment_fill, andunattributed. - Package JSON adds a
partitionsarray per version with partition size, matched image, image size, free bytes, and used percentage. - Comparison keys are stable library paths, not basename-only names.
- Reports are local engineering output; they are not firmware artifacts.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

