cozzin
코찐 기술 블로그
cozzin
전체 방문자
오늘
어제
  • 분류 전체보기
    • Kotlin
    • 백엔드
    • iOS
      • Swift
      • SwiftUI
      • Combine
      • Architecture
    • 개발환경
    • 세미나
    • 생각정리
    • 스터디
    • CS
      • Refactoring
      • OS

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • LinkedIn
  • 강의

공지사항

인기 글

태그

  • Swift
  • multicast
  • 리팩토링
  • WWDC21
  • 디자인패턴
  • slide-over
  • 테스트
  • Ribs
  • Combine
  • CS
  • 운영체제
  • 컴퓨터공학
  • SwiftUI
  • darkmode
  • WWDC
  • os
  • XCode
  • Warning
  • 워닝제거
  • ios

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
cozzin

코찐 기술 블로그

[WWDC21] Ultimate application performance survival guide
iOS

[WWDC21] Ultimate application performance survival guide

2021. 7. 8. 13:32
반응형

https://developer.apple.com/videos/play/wwdc2021/10181/

툴이 되게 많음

 

자 이렇게 따라가 봅시다

image

Battery usage

  • 배터리 관리를 잘해줘야 앱도 오래 머물 수 있음
  • CPU, Networking, Location, GPU, Audio, Bluetooth 신경 써야함

스프레이 버튼 > Energy Impact 들어가서 Energy Impact 확인할 수 있음

imageimage

MetricKit

원격 측정 프레임워크. 릴리즈된 앱을 측정하는데 도움이 될 수 있음

image

class AppMetrics: MXMetricManagerSubscriber {
    init() {
        let shared = MXMetricManager.shared
        shared.add(self)
    }

    deinit {
        let shared = MXMetricManager.shared
        shared.remove(self)
    }

    // Receive daily metrics
    func didReceive(_ payloads: [MXMetricPayload]) {
        // Process metrics
    }

    // Receive diagnostics
    func didReceive(_ payloads: [MXDiagnosticPayload]) {
        // Process metrics
    }
}

앱 사용 퍼포먼스 -> 애플 서버에 전달됨 -> Xcode Organizer에서 볼 수 있음

image

Organizer 켜면 Battery Usage 확인할 수 있음. 최근 16개 버전 볼 수 있음

image

Regression Pane

image

어떤 부분이 이슈를 만들어내는지 보려면, Report 아래에 있는 Energy Organizer를 보면 됨

image

배터리 성능 측정에 대해 더 알아보기

  • Improving battery life and performance, WWDC19 (https://developer.apple.com/videos/play/wwdc2019/417/)
  • Analyze HTTP traffic in instruments, WWDC21 (https://developer.apple.com/videos/play/wwdc2021/10212/)

Hang rate and scrolling

  • Hang은 앱이 250밀리초 이상 사용자 입력 또는 작업에 응답하지 않는 경우

여기서 빨간 막대는 스크롤 경험이 안좋을 수록 표시됨 (렉 걸리는 그 느낌...)

image

Instruments로 어느 부분이 Hang을 일으키는지 분석할 수 있음

image

스크롤 경험을 XCTest로 측정할 수 있음

func testScrollingAnimationPerformance() throws {

    app.launch()
    app.staticTexts["Meal Planner"].tap()
    let foodCollection = app.collectionViews.firstMatch

    let measureOptions = XCTMeasureOptions()
    measureOptions.invocationOptions = [.manuallyStop] // 이렇게 지정하면 블록 중간에 stopMeasuring 지정할 수 있음

    measure(metrics: [XCTOSSignpostMetric.scrollDecelerationMetric], // 스크롤 측정
    options: measureOptions) {
        foodCollection.swipeUp(velocity: .fast) // start 
        stopMeasuring()
        foodCollection.swipeDown(velocity: .fast) // reset
    }
}

MetricKit을 구성하면 iOS 14에서는 24시간 간격으로 원격 이슈 파악 가능하고

image

iOS 15에서는 즉시 이슈 파악 가능함...!!!!

image

func startAnimating() {
    // Mark the beginning of animations
    mxSignpostAnimationIntervalBegin(
        log: MXMetricManager.makeLogHandle(category: "animation_telemetry"), 
        name: "custom_animation”)
}

func animationDidComplete() {
    // Mark the end of the animation to receive the collected hitch rate telemetry
    mxSignpost(OSSignpostType.end, 
        log: MXMetricManager.makeLogHandle(category: "animation_telemetry"), 
        name: "custom_animation")
}

더 알아보기
Understand and eliminate hangs from your app, WWDC21 - https://developer.apple.com/videos/play/wwdc2021/10258/

Disk Writes

Instruments 통해서 Disk I/O 확인할 수 있음

image

Disk Usage를 XCTest로 측정할 수 있음
baseline를 설정해서 그것보다 퍼포먼스가 안나오면 테스트 실패되게 만들 수 있음

// Example performance XCTest

func testSaveMeal() {
    let app = XCUIApplication()
    let options = XCTMeasureOptions()
    options.invocationOptions = [.manuallyStart]

    measure(metrics: [XCTStorageMetric(application: app)], options: options) {
        app.launch()
        startMeasuring()

        let firstCell = app.cells.firstMatch
        firstCell.buttons["Save meal"].firstMatch.tap()

        let savedButton = firstCell.buttons["Saved"].firstMatch
        XCTAssertTrue(savedButton.waitForExistence(timeout: 2))
    }
}

이미 출시된 버전은 Organizer를 통해 확인 가능

image

Report 섹션 아래의 Disk Writes
앱이 24시간 내에 1GB 이상 디스크 쓰기를 하면 Report

image

Xcode13 에서는 어떻게 고쳐야할지 Insights 를 제공함.

image

Disk Write 이슈 더 알아보기:
Diagnose power and performance regressions in your app, WWDC21 - https://developer.apple.com/videos/play/wwdc2021/10087/

Launch time and termination

  • 실행 시간: 실행 시간이 길면 유저는 짜증남...
  • 종료 관리: 앱이 종료되게 되면 앱을 다시 사용할 떄도 실행하는 시간이 또 걸림

Organizer > Launch time

image

Organizer > Termination

image

Instruments > App Launch

image

앞서 본 것 처럼 XCTest를 활용할 수도 있음

MetricKit이 앱에 구현되어 있으면 daily metric payload로 매일 받아볼 수 있음

왜 앱이 종료되는지 자세히 확인하고 싶다면?
Why is my app getting killed?, WWDC 20 - https://developer.apple.com/videos/play/wwdc2020/10078/

Memory

Organizer > Memory

image

Instruments > Leaks, Allocations, VM Tracker

image

MetricKit

// Collect memory telemetry

func saveAppAssets() {
    mxSignpost(OSSignpostType.begin, 
        log: MXMetricManager.makeLogHandle(category: "memory_telemetry"), 
        name: "custom_memory")

    // save app metadata

    mxSignpost(OSSignpostType.end, 
        log: MXMetricManager.makeLogHandle(category: "memory_telemetry"), 
        name: "custom_memory")
}

더 알아보기:
Detect and diagnose memory issues https://github.com/cozzin/cozzin.github.io/issues/36
https://developer.apple.com/videos/play/wwdc2021/10180/

Next step

image

  • https://developer.apple.com/videos/play/wwdc2020/10076/
  • https://developer.apple.com/videos/play/wwdc2020/10081 MetricKit을 잘 쓰면 진짜 좋을 듯
반응형
저작자표시 (새창열림)

'iOS' 카테고리의 다른 글

iPad Slide-over 키보드 높이 계산 이슈 해결  (0) 2021.06.15
Main Thread 무한 루프 문제해결 과정  (0) 2021.06.14
커스텀 UIInputView height에 SafeArea 반영하기  (0) 2021.04.28
Swift 객체 외부에서 객체가 해제되는 것 감지하기  (0) 2021.04.20
@testable import로 연결한 모듈에서 Undefined symbol이 발생하는 이슈 대응  (0) 2021.04.17
    'iOS' 카테고리의 다른 글
    • iPad Slide-over 키보드 높이 계산 이슈 해결
    • Main Thread 무한 루프 문제해결 과정
    • 커스텀 UIInputView height에 SafeArea 반영하기
    • Swift 객체 외부에서 객체가 해제되는 것 감지하기
    cozzin
    cozzin
    Software Engineer

    티스토리툴바