Mobile Development 25 min read

Optimizing iOS App Bundle Size with HEIC Images and Unused Class Detection

The guide shows how to shrink a Baidu iOS app by converting PNGs to HEIC within Asset Catalogs—leveraging Xcode’s actool for compression, avoiding pngquant‑induced alpha issues, and employing combined static LinkMap/Mach‑O parsing and runtime isa‑flag checks to prune never‑instantiated classes.

Baidu Geek Talk
Baidu Geek Talk
Baidu Geek Talk
Optimizing iOS App Bundle Size with HEIC Images and Unused Class Detection

This article presents practical optimization techniques for the Baidu iOS app, focusing on HEIC image usage and unused class detection to reduce bundle size.

HEIC Image Format : HEIC (High Efficiency Image File) introduced in iOS 11 offers better compression than JPEG/PNG. Three conversion methods are discussed: macOS built‑in image conversion, the sips command, and ImageMagick’s convert . Example sips usage: sips -s format heic -s formatOptions default [email protected] --out [email protected]

HEIC in iOS : iOS frameworks (ImageIO, Core Image, UIKit, PhotoKit) support HEIC. Images can be placed in the app Bundle or in an Asset Catalog. Asset Catalog is recommended because Xcode’s actool compresses assets and ensures compatibility across iOS versions.

Compatibility Findings :

PNG → HEIC conversion reduces file size by 10‑70%.

HEIC images in Asset Catalog are compatible with iOS 10+; in Bundle they only decode on iOS 12+.

Alpha‑channel PNGs that have been lossily compressed with pngquant exhibit green‑border or white‑pixel artifacts on iOS 11‑14 when converted to HEIC via sips . Direct ImageIO conversion preserves correct alpha.

Asset Catalog vs Bundle : After actool processing, the on‑disk size of assets may differ from the original file size. Sample actool command for a generic build: /Applications/Xcode.app/Contents/Developer/usr/bin/actool --output-format human-readable-text --notices --warnings --export-dependency-info ... --minimum-deployment-target 16.0 --platform iphoneos --compile ...

Best Practices :

Prefer HEIC in Asset Catalog for iOS 10+ support.

Avoid pngquant on PNGs that will be converted to HEIC.

Use Git hooks to flag large resources (>20 KB) and suggest optimal compression.

Unused Class Detection : Combines static analysis (LinkMap + Mach‑O parsing) and dynamic analysis (runtime isa flag RW_INITIALIZED ) to identify classes that are never instantiated. Static steps include extracting __objc_classlist and __objc_classrefs sections with otool . Dynamic steps involve iterating over all loaded classes and checking isInitialized() via a custom struct that mirrors the Objective‑C runtime layout.

Summary :

HEIC provides significant size savings but requires careful handling of alpha channels.

Asset Catalog is the safest container for HEIC assets.

Static + dynamic unused‑class detection effectively reduces code bloat.

iOSbundle optimizationimage compressionstatic analysisHEICAsset CatalogUnused Class Detection
Baidu Geek Talk
Written by

Baidu Geek Talk

Follow us to discover more Baidu tech insights.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.