Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Optimizing Mobile Apps: Tips and Tricks

Avatar for Itay Brenner Itay Brenner
September 04, 2023

Optimizing Mobile Apps: Tips and Tricks

Avatar for Itay Brenner

Itay Brenner

September 04, 2023
Tweet

More Decks by Itay Brenner

Other Decks in Programming

Transcript

  1. Tip 1: Stripping Binary Symbols • They are not required

    to be in production apps. • We can still get fully symbolicated crash reports using dSYMs.
  2. Tip 1: Stripping Binary Symbols #!/bin/bash set -e # if

    [ "Release" = "${CONFIGURATION}" ]; then # Only do this for release builds # Path to the app directory APP_DIR_PATH="${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}" # Strip main binary strip -rSTx "${APP_DIR_PATH}/${EXECUTABLE_NAME}" # Path to the Frameworks directory APP_FRAMEWORKS_DIR="${APP_DIR_PATH}/Frameworks" # Strip symbols from frameworks, if Frameworks/ exists at all # ... as long as the framework is NOT signed by Apple if [ -d "${APP_FRAMEWORKS_DIR}" ] then find "${APP_FRAMEWORKS_DIR}" -type f -perm +111 -maxdepth 2 -mindepth 2 -exec bash -c 'codesign -v -R="anchor apple" "{}" &> /dev/null || (echo "{}" && strip -rSTx "{}")' \\; fi # fi
  3. Tip 2: Sharing Code and Assets • Share code and

    assets using dynamic frameworks. • Load frameworks from the app bundle using runtime search paths (@rpath).
  4. Tip 3: Optimizing Assets • Xcode converts vectors (SVG and

    PDF) to PNGs when building. • Vectors file size do not represent final size on the app.
  5. Tip 4: Keep the Main Thread Light • Delays on

    the Main Thread lead to poor user experience. • Offload heavy task to the background. Including: ◦ JSON loading. ◦ Image decoding.
  6. Tip 4: Keep the Main Thread Light let image =

    UIImage(named: "myNAME") image.prepareForDisplay { [weak self] decodedImage in self?.imageView.image = decodedImage }
  7. Tip 5: Prefer Static Dispatch class Animal { // Might

    not use Static Dispatch func eat() { // Do something } } final class Dog: Animal { // Swift will try to use Static Dispatch override func eat() { } }
  8. Tip 5: Prefer Static Dispatch class Animal { func eat()

    { // Swift will use Static Dispatch findFood() } private func findFood() { } }
  9. Tip 6: Understanding your Package Manager - SPM Cons: •

    Limited support for mixed language projects. • Lower number of available dependencies (mainly old and legacy). Pros: • Supported by Apple. • Integrates easily with Xcode.
  10. Tip 6: Understanding your Package Manager - CocoaPods Cons: •

    May modify our project files (which might involve git conflicts later). Pros: • Well maintained by the community. • Supports plugins.
  11. Tip 7: Optimizing CoreML Models • Try half precision models.

    • Keep trying lower precision models to keep improving performance and weight.
  12. Tip 8: Never stop improving New tools in Swift 5.9:

    • Macros • If and swift expressions • Noncopyable structs and enums • Consume operator