맛동산이

앱사이즈 최적화 하는 5가지 방법 본문

앱/Swift

앱사이즈 최적화 하는 5가지 방법

진ddang 2024. 2. 25. 17:30

공식 홈페이지 가이드

bookmark

bookmark

최적화를 하기 앞서서, 앱 사이즈 체크

앱사이즈 최적화 보고서

  • 통합워크플로우를 생성해서 app thinning size report를 자동생성하도록 할수있다.
  • 이를 통해 매번 빌드 배포시, app thinning size를 체크할수 있게 된다.

앱사이즈 최적화 보고서 만드는법

1. 직접 생성하는 법

  1. Archive your app in Xcode.
  2. Export your archived app as an Ad Hoc, Development, or Enterprise build.
  3. In the sheet for setting the development distribution options, choose “All compatible device variants” for app thinning.
  4. Sign your app and export it to your Mac.

2. 자동으로 생성하도록 xcodebuilder를 사용하는 법

  • Add the key “thinning” in your export options plist file with the value “” (Keep the angular braces in your export option plist file.)
  • add the following command in your build script to export the archive with report

xcodebuild -exportArchive -archivePath .xcarchive -exportPath -exportOptionsPlist .plist

보고서를 보는법

  • universal IPA file for older devices. This single IPA file contains assets and binaries for all variants of your app.
  • Thinned IPA files for each variant of your app. These files contain assets and binaries for only one variant.
  • In the output folder, it generates the app size report file with the name “App Thinning Size Report.txt”

앱 사이즈 줄이는 대표적인 방법

  • 에셋 카탈로그 사용하기
  • App thinning 사용하기(app thinning, slicing, bitcode, on demand resource)
  • 사용되지 않는 코드와 리소스 제거
  • 코드를 통한 최적화
  • LLVM optimization levels

app thinning

app thinning과, on demand resource, slicing이 가능하도록 설정

Untitled.png

사용되지 않는 코드 제거와 최적화

아래의 3가지를 효과적으로 사용해서 최적화를 진행한다.

  • Structs instead of Classes: Structs take up less memory than classes, making them a great choice for small data structures.
  • Enumerations: Enumerations can be used to represent a set of values, which can help reduce the size of your code.
  • Optionals: Optionals can help you avoid unnecessary code and reduce the size of your app.

LLVM 최적화

bookmark

bookmark

None [-O0]

  • No attempt to optimize the code.
  • The goal is to reduce the cost of compilation
  • Makes debugging produce the expected results and statements are independent
  • Used during development when you are focused on debugging and need a fast compile time. Not for shipping your executable.

Fast [-O, O1]

  • Does simple optimizations to Increase code performance while minimizing the impact to compile time.

Faster [-O2]

  • Increases both compilation time and the performance of generated code.

Fastest [-O3]

  • This option can increase the size of generated code as the compiler performs aggressive inlining of functions. (This option is generally not recommended.)

Fastest, Smallest [-Os]

  • Performs all optimizations that do not typically increase code size.
  • Suitable for shipping code because it gives your executable a smaller memory footprint.

Fastest, Aggressive optimization [-Ofast]

  • This setting enables Fastest but also enables aggressive optimizations that may break strict standards compliance but should work well on well-behaved code.

Untitled.png

반응형