cozzin / cozzin.github.io

Blog

Home Page:https://cozzin.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[WWDC21] Ultimate application performance survival guide

cozzin opened this issue · comments

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

툴이 되게 많음
image

자 이렇게 따라가 봅시다
image

Battery usage

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

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

image

image

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

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

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 #36
https://developer.apple.com/videos/play/wwdc2021/10180/

Next step

image