iOS Binary Size Reduction
Use this skill for: Swift/Xcode apps where executable and package size are above target and size reduction must preserve app behavior, security, and startup quality.
0) Inputs
workspace_or_project: .xcworkspace (preferred) or .xcodeproj
scheme
configuration: Release (default)
risk_level: low | balanced | aggressive
size_budget_mb: optional target reduction threshold
min_gain_mb: minimum gain to keep a change (0.3 MB default)
slice_scope: all or explicit family/OS slices
1) Guardrails
- Never apply unsafe production runtime settings:
-Ounchecked, -enforce-exclusivity=unchecked, or equivalent safety suppression flags.
- Never remove
dSYM generation. Keep symbol upload and crash-symbolication verified.
- Do not merge app behavior changes (asset migration, reflection, feature gating) without passing functional gates.
- Use one risk tier at a time; revert immediately on gate failure.
- Before edits, pin environment metadata (
xcodebuild -version, swift --version, destination, git SHA) and rerun the baseline pipeline once as a no-op control.
- Capture and apply settings per target (for example: app target first, then extensions/widgets), not only project-level.
2) Baseline capture (required)
Before any mutation:
- Collect build settings snapshot:
SWIFT_OPTIMIZATION_LEVEL
SWIFT_COMPILATION_MODE
DEAD_CODE_STRIPPING
STRIP_INSTALLED_PRODUCT
STRIP_SWIFT_SYMBOLS
LD / linker flags (OTHER_LDFLAGS)
ASSETCATALOG_COMPILER_OPTIMIZATION
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES
SWIFT_REFLECTION_METADATA_LEVEL
LD_RUNPATH_SEARCH_PATHS
- Capture size baselines from clean Release archive:
ipa size, app bundle size
- Mach-O
__TEXT and section split (xcrun size -m)
- symbol table size, dSYM size
- symbolication check against one controlled crash sample
- Capture baseline quality/perf gates:
- cold launch time and memory peak
- targeted smoke suite pass/fail
- launch crash/no-signature regressions
- Record immutable environment metadata:
xcodebuild -version, swift --version
- build destination (
-destination)
- git
HEAD and clean/dirty state
- scheme/configuration and archive variant
- Use a reproducible baseline command template and reuse it verbatim for repeatability:
- Workspace:
xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -configuration Release -destination "$DESTINATION" -archivePath "$TMP_ARCHIVE" clean archive
- Project fallback:
xcodebuild -project "$PROJECT" -scheme "$SCHEME" -configuration Release -destination "$DESTINATION" -archivePath "$TMP_ARCHIVE" clean archive
- Export:
xcodebuild -exportArchive -archivePath "$TMP_ARCHIVE" -exportPath "$TMP_IPA_PATH" -exportOptionsPlist "$EXPORT_OPTIONS"
3) Pass scheduler (default execution order)
Tier 1 — Conservative
Apply in sequence, keep all gates green.
- Run a deterministic Release-only pipeline only:
clean
archive (-configuration Release)
- fixed-name export of
ipa
- Compare only this Release archive pair against future Release artifacts; ignore Debug artifacts and ephemeral caches.
- Enable deterministic post-processing:
DEPLOYMENT_POSTPROCESSING = YES, STRIP_INSTALLED_PRODUCT = YES
STRIP_SWIFT_SYMBOLS = YES
DEAD_CODE_STRIPPING = YES
SWIFT_COMPILATION_MODE = WholeModule
- Remove unused localizations and legacy assets only with an explicit locale/asset inventory
ASSETCATALOG_COMPILER_OPTIMIZATION = space, prune unused scales/device families; spot-check touched UI flows visually
- Strip raster metadata (
STRIP_PNG_TEXT = YES) where legal/compliance requirements allow it
- Unembed or prune unnecessary resource-heavy bundles
Tier 2 — Performance/size tradeoff
Only enable if Tier 1 passes.
SWIFT_OPTIMIZATION_LEVEL = -Osize
- Enable
LLVM_LTO (incremental/partial first)
- Slice pruning: remove unused architectures
- Set
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO only when precomputed target deployment matrix remains valid (per platform/extension/device family).
- Dependency minimization pass (SPM/CocoaPods): remove unused targets/features/modules
- App-thinning report validation and variant-specific packaging checks
Tier 3 — Conditional / high risk
Enable only with explicit approval when constraints are still missed.
Required preconditions:
- Tier 1 and 2 must have passed two consecutive measured runs.
- Size delta trend must be stable (median repeat variance below configured noise floor).
SWIFT_REFLECTION_METADATA_LEVEL = without-names, then selective none
- Symbol export hardening (
GCC_SYMBOLS_PRIVATE_EXTERN, exported/unexported symbol map strategy)
- Remove aggressive linker retention flags (
-ObjC, -all_load) only after runtime validation
- Move optional heavy payload to on-demand/background assets strategy
- Framework split/restructuring or feature-module extraction where architecture allows
4) Technique catalogue with trade-off notes
P1: Release-only clean baseline control. Low risk, required for valid deltas.
P2: DEPLOYMENT_POSTPROCESSING and STRIP_INSTALLED_PRODUCT are deterministic, low-risk size wins.
P3: STRIP_SWIFT_SYMBOLS = YES reduces size and improves artifact hygiene; requires strict dSYM retention.
P4: DEAD_CODE_STRIPPING = YES gives medium-high size gain; low behavior risk with smoke tests.
P5: Whole-module compilation is strong for dead boundaries; compile time can increase.
P6: Localization pruning gives high ROI only with accurate usage inventory.
P7: Asset catalog optimization is often highest ROI among Tier 1 items; visual regressions possible.
P8: STRIP_PNG_TEXT = YES can improve size; preserve legal/compliance metadata.
P9: Resource bundle pruning is strong but UX-sensitive.
P10: -Osize is effective for binary shrink; potential hot-path performance regression.
P11: LLVM_LTO typically improves size/perf but increases toolchain CPU/time.
P12: Architecture pruning is deterministic if target matrix is validated.
P13: ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO lowers size where safe; verify all target configurations.
P14: Dependency minimization has high value-to-effort, but functional side-effect risk is highest here.
P15: App-thinning validation is low risk, high confidence for deployment compatibility.
P16: Reflection metadata reduction is substantial, may break dynamic reflection users.
- Validation checklist before and after enabling:
JSONDecoder/Decodable hot paths still roundtrip correctly
- plugin/discovery paths using runtime type lookup
Mirror and dynamic cast behavior
- serialization framework smoke paths (Codable/custom coders)
P17: Export map hardening improves security posture but can break external integrations.
P18: Removing -ObjC / -all_load is risky if runtime registration depends on it.
P19: On-demand payload can greatly reduce install size; adds runtime fetch and fallback complexity.
P20: Module/framework extraction improves long-term size/control but high refactor risk.
5) Security, quality, and performance comparison
- Security priority (best to worse): export hardening (
P17) → deterministic stripping (P3,P4) → architecture/asset changes (P12,P7) → optimization/link choices (P10,P11) → reflection and linkage edits (P16,P18).
- Quality priority (best): resource and dependency cleanup (
P6,P7,P14) → conservative compile/link toggles (P5,P10,P11) → reflection/payload changes (P16,P19).
- Perf priority (best):
P11 and controlled reflection tuning (P16) are often neutral to positive; P10 can hurt hot paths.
6) Required validation gates after every pass
- Size gate:
ipa, app bundle, __TEXT, and install-eligible slices compared against baseline.
- Functional gate: app launches + critical flows + startup path coverage.
- Stability gate: controlled crash samples must symbolicate with uploaded dSYM.
- Runtime gate: post-change launch and memory budgets respected.
- Security gate: signing, entitlements, and crash-reportability unchanged.
- Reversion gate: if actual gain <
min_gain_mb or any gate fails, revert only that pass.
Gate execution rule:
- Run each gate twice (or one warm-up + one measured run at minimum); use median or stable mean for gate decisions.
- If either run is outlier by configured noise floor, rerun once before failing pass.
Default per-pass budgets unless overridden:
- size gain threshold:
min_gain_mb (or 0.3MB)
- launch: +5% or +100ms
- memory peak: +10MB max
- critical flows: no regressions
- crash sample symbolication: 100%
7) Evaluation report format
Produce a single report per run containing:
run_id, xcode_version, swift_version, git_sha, destination, risk_level
run_started_at, run_ended_at, run_duration_seconds
- Baseline and final size rows (
ipa, app, __TEXT, symbol bytes, dSYM bytes)
- Per-pass table entries:
pass_id
settings_changed
size_delta_mb
cumulative_gain_mb
pass_started_at, pass_ended_at, pass_duration_seconds
pass_status (applied, reverted, skipped)
security_impact
quality_impact
performance_delta
gate_status
rollback
notes
- Rollback log
- Final recommendation + confidence
8) Exit criteria and next-step policy
- Stop on first pass with acceptable reduction while all gates pass.
- If still above target, continue next tier.
- For
low risk_level, never run P14 or above without explicit approval.
- For
balanced, stop at tier 2 unless explicitly authorized.
- For
aggressive, keep user-informed checkpoints before tier 3.
9) Minimal output JSON schema
{
"run_id": "ios-size-YYYYMMDD-###",
"xcode_version": "15.x",
"swift_version": "5.x",
"git_sha": "",
"destination": "",
"risk_level": "low|balanced|aggressive",
"run_started_at": "2026-03-03T12:00:00Z",
"run_ended_at": "2026-03-03T12:03:24Z",
"run_duration_seconds": 204,
"baseline": {
"ipa_mb": 0.0,
"app_mb": 0.0,
"text_section_mb": 0.0,
"symbols_mb": 0.0,
"dsym_mb": 0.0
},
"final": {
"ipa_mb": 0.0,
"app_mb": 0.0,
"text_section_mb": 0.0,
"symbols_mb": 0.0,
"dsym_mb": 0.0
},
"cumulative_gain_mb": 0.0,
"passes": [
{
"id": "P4",
"gain_mb": 0.0,
"settings_changed": ["DEAD_CODE_STRIPPING=YES"],
"size_delta_mb": 0.0,
"cumulative_gain_mb": 0.0,
"pass_started_at": "2026-03-03T12:01:00Z",
"pass_ended_at": "2026-03-03T12:01:42Z",
"pass_duration_seconds": 42,
"pass_status": "applied",
"security": "low|medium|high",
"quality": "low|medium|high",
"performance_delta": "improved|neutral|degraded",
"gate_status": "pass|fail",
"rollback": false,
"notes": "reason"
}
]
}
1---
2name: ios-binary-size-reduction
3description: Use when an iOS app binary/app package needs size reduction with risk-aware optimization, security-aware checks, and verifiable build/runtime evaluation so results are safe and repeatable.
4metadata:
5 source: https://skillmd.com/skills/aibot88/ios-binary-size-reduction
6---
7
8# iOS Binary Size Reduction
9
10Use this skill for: Swift/Xcode apps where executable and package size are above target and size reduction must preserve app behavior, security, and startup quality.
11
12## 0) Inputs
13
14- `workspace_or_project`: `.xcworkspace` (preferred) or `.xcodeproj`
15- `scheme`
16- `configuration`: `Release` (default)
17- `risk_level`: `low | balanced | aggressive`
18- `size_budget_mb`: optional target reduction threshold
19- `min_gain_mb`: minimum gain to keep a change (`0.3` MB default)
20- `slice_scope`: `all` or explicit family/OS slices
21
22## 1) Guardrails
23
24- Never apply unsafe production runtime settings: `-Ounchecked`, `-enforce-exclusivity=unchecked`, or equivalent safety suppression flags.
25- Never remove `dSYM` generation. Keep symbol upload and crash-symbolication verified.
26- Do not merge app behavior changes (asset migration, reflection, feature gating) without passing functional gates.
27- Use one risk tier at a time; revert immediately on gate failure.
28- Before edits, pin environment metadata (`xcodebuild -version`, `swift --version`, destination, git SHA) and rerun the baseline pipeline once as a no-op control.
29- Capture and apply settings per target (for example: app target first, then extensions/widgets), not only project-level.
30
31## 2) Baseline capture (required)
32
33Before any mutation:
34
351. Collect build settings snapshot:
36 - `SWIFT_OPTIMIZATION_LEVEL`
37 - `SWIFT_COMPILATION_MODE`
38 - `DEAD_CODE_STRIPPING`
39 - `STRIP_INSTALLED_PRODUCT`
40 - `STRIP_SWIFT_SYMBOLS`
41 - `LD` / linker flags (`OTHER_LDFLAGS`)
42 - `ASSETCATALOG_COMPILER_OPTIMIZATION`
43 - `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES`
44 - `SWIFT_REFLECTION_METADATA_LEVEL`
45 - `LD_RUNPATH_SEARCH_PATHS`
462. Capture size baselines from clean Release archive:
47 - `ipa` size, app bundle size
48 - Mach-O `__TEXT` and section split (`xcrun size -m`)
49 - symbol table size, dSYM size
50 - symbolication check against one controlled crash sample
513. Capture baseline quality/perf gates:
52 - cold launch time and memory peak
53 - targeted smoke suite pass/fail
54 - launch crash/no-signature regressions
554. Record immutable environment metadata:
56 - `xcodebuild -version`, `swift --version`
57 - build destination (`-destination`)
58 - git `HEAD` and clean/dirty state
59 - scheme/configuration and archive variant
605. Use a reproducible baseline command template and reuse it verbatim for repeatability:
61 - Workspace:
62 `xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -configuration Release -destination "$DESTINATION" -archivePath "$TMP_ARCHIVE" clean archive`
63 - Project fallback:
64 `xcodebuild -project "$PROJECT" -scheme "$SCHEME" -configuration Release -destination "$DESTINATION" -archivePath "$TMP_ARCHIVE" clean archive`
65 - Export:
66 `xcodebuild -exportArchive -archivePath "$TMP_ARCHIVE" -exportPath "$TMP_IPA_PATH" -exportOptionsPlist "$EXPORT_OPTIONS"`
67
68## 3) Pass scheduler (default execution order)
69
70### Tier 1 — Conservative
71
72Apply in sequence, keep all gates green.
73
741. Run a deterministic Release-only pipeline only:
75 1) `clean`
76 2) `archive` (`-configuration Release`)
77 3) fixed-name export of `ipa`
78 - Compare only this Release archive pair against future Release artifacts; ignore Debug artifacts and ephemeral caches.
792. Enable deterministic post-processing: `DEPLOYMENT_POSTPROCESSING = YES`, `STRIP_INSTALLED_PRODUCT = YES`
803. `STRIP_SWIFT_SYMBOLS = YES`
814. `DEAD_CODE_STRIPPING = YES`
825. `SWIFT_COMPILATION_MODE = WholeModule`
836. Remove unused localizations and legacy assets only with an explicit locale/asset inventory
847. `ASSETCATALOG_COMPILER_OPTIMIZATION = space`, prune unused scales/device families; spot-check touched UI flows visually
858. Strip raster metadata (`STRIP_PNG_TEXT = YES`) where legal/compliance requirements allow it
869. Unembed or prune unnecessary resource-heavy bundles
87
88### Tier 2 — Performance/size tradeoff
89
90Only enable if Tier 1 passes.
91
9210. `SWIFT_OPTIMIZATION_LEVEL = -Osize`
9311. Enable `LLVM_LTO` (incremental/partial first)
9412. Slice pruning: remove unused architectures
9513. Set `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO` only when precomputed target deployment matrix remains valid (per platform/extension/device family).
9614. Dependency minimization pass (SPM/CocoaPods): remove unused targets/features/modules
9715. App-thinning report validation and variant-specific packaging checks
98
99### Tier 3 — Conditional / high risk
100
101Enable only with explicit approval when constraints are still missed.
102Required preconditions:
103- Tier 1 and 2 must have passed two consecutive measured runs.
104- Size delta trend must be stable (median repeat variance below configured noise floor).
105
10616. `SWIFT_REFLECTION_METADATA_LEVEL = without-names`, then selective `none`
10717. Symbol export hardening (`GCC_SYMBOLS_PRIVATE_EXTERN`, exported/unexported symbol map strategy)
10818. Remove aggressive linker retention flags (`-ObjC`, `-all_load`) only after runtime validation
10919. Move optional heavy payload to on-demand/background assets strategy
11020. Framework split/restructuring or feature-module extraction where architecture allows
111
112## 4) Technique catalogue with trade-off notes
113
114- `P1`: Release-only clean baseline control. Low risk, required for valid deltas.
115- `P2`: `DEPLOYMENT_POSTPROCESSING` and `STRIP_INSTALLED_PRODUCT` are deterministic, low-risk size wins.
116- `P3`: `STRIP_SWIFT_SYMBOLS = YES` reduces size and improves artifact hygiene; requires strict dSYM retention.
117- `P4`: `DEAD_CODE_STRIPPING = YES` gives medium-high size gain; low behavior risk with smoke tests.
118- `P5`: Whole-module compilation is strong for dead boundaries; compile time can increase.
119- `P6`: Localization pruning gives high ROI only with accurate usage inventory.
120- `P7`: Asset catalog optimization is often highest ROI among Tier 1 items; visual regressions possible.
121- `P8`: `STRIP_PNG_TEXT = YES` can improve size; preserve legal/compliance metadata.
122- `P9`: Resource bundle pruning is strong but UX-sensitive.
123- `P10`: `-Osize` is effective for binary shrink; potential hot-path performance regression.
124- `P11`: `LLVM_LTO` typically improves size/perf but increases toolchain CPU/time.
125- `P12`: Architecture pruning is deterministic if target matrix is validated.
126- `P13`: `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO` lowers size where safe; verify all target configurations.
127- `P14`: Dependency minimization has high value-to-effort, but functional side-effect risk is highest here.
128- `P15`: App-thinning validation is low risk, high confidence for deployment compatibility.
129- `P16`: Reflection metadata reduction is substantial, may break dynamic reflection users.
130 - Validation checklist before and after enabling:
131 - `JSONDecoder`/`Decodable` hot paths still roundtrip correctly
132 - plugin/discovery paths using runtime type lookup
133 - `Mirror` and dynamic cast behavior
134 - serialization framework smoke paths (Codable/custom coders)
135- `P17`: Export map hardening improves security posture but can break external integrations.
136- `P18`: Removing `-ObjC` / `-all_load` is risky if runtime registration depends on it.
137- `P19`: On-demand payload can greatly reduce install size; adds runtime fetch and fallback complexity.
138- `P20`: Module/framework extraction improves long-term size/control but high refactor risk.
139
140## 5) Security, quality, and performance comparison
141
142- **Security priority** (best to worse): export hardening (`P17`) → deterministic stripping (`P3`,`P4`) → architecture/asset changes (`P12`,`P7`) → optimization/link choices (`P10`,`P11`) → reflection and linkage edits (`P16`,`P18`).
143- **Quality priority** (best): resource and dependency cleanup (`P6`,`P7`,`P14`) → conservative compile/link toggles (`P5`,`P10`,`P11`) → reflection/payload changes (`P16`,`P19`).
144- **Perf priority** (best): `P11` and controlled reflection tuning (`P16`) are often neutral to positive; `P10` can hurt hot paths.
145
146## 6) Required validation gates after every pass
147
1481. Size gate: `ipa`, app bundle, `__TEXT`, and install-eligible slices compared against baseline.
1492. Functional gate: app launches + critical flows + startup path coverage.
1503. Stability gate: controlled crash samples must symbolicate with uploaded dSYM.
1514. Runtime gate: post-change launch and memory budgets respected.
1525. Security gate: signing, entitlements, and crash-reportability unchanged.
1536. Reversion gate: if actual gain < `min_gain_mb` or any gate fails, revert only that pass.
154
155Gate execution rule:
156- Run each gate twice (or one warm-up + one measured run at minimum); use median or stable mean for gate decisions.
157- If either run is outlier by configured noise floor, rerun once before failing pass.
158
159Default per-pass budgets unless overridden:
160- size gain threshold: `min_gain_mb` (or 0.3MB)
161- launch: +5% or +100ms
162- memory peak: +10MB max
163- critical flows: no regressions
164- crash sample symbolication: 100%
165
166## 7) Evaluation report format
167
168Produce a single report per run containing:
169
170- `run_id`, `xcode_version`, `swift_version`, `git_sha`, `destination`, `risk_level`
171- `run_started_at`, `run_ended_at`, `run_duration_seconds`
172- Baseline and final size rows (`ipa`, `app`, `__TEXT`, symbol bytes, dSYM bytes)
173- Per-pass table entries:
174 - `pass_id`
175 - `settings_changed`
176 - `size_delta_mb`
177 - `cumulative_gain_mb`
178 - `pass_started_at`, `pass_ended_at`, `pass_duration_seconds`
179 - `pass_status` (`applied`, `reverted`, `skipped`)
180 - `security_impact`
181 - `quality_impact`
182 - `performance_delta`
183 - `gate_status`
184 - `rollback`
185 - `notes`
186- Rollback log
187- Final recommendation + confidence
188
189## 8) Exit criteria and next-step policy
190
191- Stop on first pass with acceptable reduction while all gates pass.
192- If still above target, continue next tier.
193- For `low` risk_level, never run `P14` or above without explicit approval.
194- For `balanced`, stop at tier 2 unless explicitly authorized.
195- For `aggressive`, keep user-informed checkpoints before tier 3.
196
197## 9) Minimal output JSON schema
198
199```json
200{
201 "run_id": "ios-size-YYYYMMDD-###",
202 "xcode_version": "15.x",
203 "swift_version": "5.x",
204 "git_sha": "",
205 "destination": "",
206 "risk_level": "low|balanced|aggressive",
207 "run_started_at": "2026-03-03T12:00:00Z",
208 "run_ended_at": "2026-03-03T12:03:24Z",
209 "run_duration_seconds": 204,
210 "baseline": {
211 "ipa_mb": 0.0,
212 "app_mb": 0.0,
213 "text_section_mb": 0.0,
214 "symbols_mb": 0.0,
215 "dsym_mb": 0.0
216 },
217 "final": {
218 "ipa_mb": 0.0,
219 "app_mb": 0.0,
220 "text_section_mb": 0.0,
221 "symbols_mb": 0.0,
222 "dsym_mb": 0.0
223 },
224 "cumulative_gain_mb": 0.0,
225 "passes": [
226 {
227 "id": "P4",
228 "gain_mb": 0.0,
229 "settings_changed": ["DEAD_CODE_STRIPPING=YES"],
230 "size_delta_mb": 0.0,
231 "cumulative_gain_mb": 0.0,
232 "pass_started_at": "2026-03-03T12:01:00Z",
233 "pass_ended_at": "2026-03-03T12:01:42Z",
234 "pass_duration_seconds": 42,
235 "pass_status": "applied",
236 "security": "low|medium|high",
237 "quality": "low|medium|high",
238 "performance_delta": "improved|neutral|degraded",
239 "gate_status": "pass|fail",
240 "rollback": false,
241 "notes": "reason"
242 }
243 ]
244}
245```