Optimize Size
Overview
Use this skill to run measured, high-leverage executable-size experiments for CaseDash. Aim for a retained build\CaseDash.exe reduction of at least 10 KiB when plausible, and keep going past the first small win while credible larger hypotheses remain.
Required Context
- Read
AGENTS.md. - Read
docs/optimize_size.mdbefore forming hypotheses. Treat it as the source of truth for size constraints, retained size shape, active negative guidance, map workflow, current baseline, and size pitfall notes. - Read
docs/build.mdfor build and validation entrypoints. - Read
docs/profile_benchmark.mdbefore changing renderer, widget layout, layout resolver, telemetry, provider sampling, or other hot paths. - Read
docs/architecture.mdand the relevantdocs/architecture/*.mdfiles before removing or bypassing package boundaries, middle-man layers, or shared abstractions.
Baseline
- Inspect
git status --short; ignore unrelated dirty work and do not revert changes made by others. - Build a fresh Release app with
.\build.cmd. - Record the shipped executable size:
(Get-Item .\build\CaseDash.exe).Length
- Generate maps with
.\build_maps.cmd. - Inspect
build\CaseDash.map.summary.txt. Use focused ad hoc map analysis when needed:
python .\tools\analyze_link_map.py .\build\CaseDash.map --top 25
- Compare the largest sections, project objects, and symbols against the maintained notes in
docs/optimize_size.md. Treat MSVC map symbol sizes as estimates.
Hypothesis Selection
Prioritize changes that can delete whole families of generated code, metadata, unwind data, resources, descriptors, or repeated cold-path machinery. Look for:
- Repeated code patterns across multiple source files or branches of one large method.
- Large methods with repeated construction, formatting, tracing, or validation chains.
- Inefficient metadata layouts, duplicated descriptor tables, redundant field facts, or extra data stored in maps.
- Repeated construction or copying of large structures, especially config, layout, telemetry, dump, and edit-tree payloads.
- APIs whose many parameters cause repeated call-site code, wide/narrow string churn, or template instantiations.
- Small fixed domains still using broad STL containers, sorting, callbacks, type erasure, or local algorithm variants.
- Middle-man abstractions that can be removed only when package boundaries and
lint.cmdarchitecture checks allow it.
Do not spend the main effort on tiny localized cleanups unless they are part of a broader measured pattern or unblock a larger deletion. Avoid experiments covered by active negative guidance in docs/optimize_size.md unless new surrounding code makes the old measurement stale, and record why the retry is justified.
Experiment Discipline
- Rank hypotheses by expected executable delta, behavioral risk, performance risk, and blast radius.
- Change one coherent hypothesis at a time.
- Prefer cold-path, resource, metadata, and linker-shape wins before changing renderer, widget draw, layout resolver, or telemetry hot paths.
- Preserve the full feature set: supported hardware providers, diagnostics, layout-edit, localization, embedded default config/localization, app icon behavior, and
/default-configbehavior. - Keep normal builds free of map generation; use
build_maps.cmdonly for size analysis. - Rebuild and remeasure after each serious experiment. If an experiment is neutral or regresses and does not improve source clarity enough to keep, revert only your own changes from that experiment.
- Leave concise
Size:comments near non-obvious retained code shapes where a conventional cleanup would likely reintroduce larger code. - Keep going until the retained executable reduction reaches at least 10 KiB, or until the remaining plausible hypotheses are too risky, already disproven, or only tiny localized wins.
Validation
- Run
.\format.cmd changedafter C++ edits; use.\format.cmd fix changedif formatting needs repair. - Run
.\lint.cmd includes changedafter retained C++ refactorings or code-shape rewrites, because size-oriented reshaping often breaks architecture, source-policy, include-style, or unused-include checks. - Run
.\build.cmdbefore every shipped-size measurement and before headless validation. - Run
.\build_maps.cmdafter the final retained build and inspectbuild\CaseDash.map.summary.txt. - Run
.\test.cmdwhen source behavior changes beyond trivial code-shape cleanup. - Prefer the smallest headless app validation that proves the edited paths. For broad size work, use
/default-config /fake /exitand put explicit diagnostics outputs underbuild\, for example:
.\build\CaseDash.exe /default-config /fake /exit /trace:build\size_optimization_validation_trace.txt /dump:build\size_optimization_validation_dump.txt /screenshot:build\size_optimization_validation_screenshot.png /layout-guide-sheet:build\size_optimization_validation_sheet.png /app-icon:build\size_optimization_validation_app_icon.png /app-icon-size:64 /save-full-config:build\size_optimization_validation_full_config.ini
- If a change can affect performance-sensitive code, build the benchmark target with
.\build.cmd Release /benchmarksand followdocs/profile_benchmark.md.
Documentation
Update docs/optimize_size.md when an experiment changes the retained size shape, active negative guidance, current baseline, or a recurring project-specific pitfall. Keep entries grouped, present-tense, and concise, with baseline/final executable sizes and important section or object deltas only when they help future decisions.
Update other maintained docs only when behavior, commands, architecture boundaries, diagnostics behavior, or provider requirements change.
Output
Summarize:
- Baseline and final
build\CaseDash.exesizes, plus the byte delta. - The hypotheses tried, including retained and rejected/neutral experiments.
- The main map evidence that explains the final result.
- Files changed and validation commands run.
- Any remaining high-value hypotheses left for the next pass.