티스토리 뷰

iOS 개발/iOS

Optimization Level + Assertion

beankhan 2021. 3. 12. 10:31

컴파일러에게 빌드를 특정 수준으로 최적화 레벨을 설정할 수 있는 옵션

 

 

빌드속도 증가를 위해서 Fastest 설정

Apple Clang - Code Generation (ObjectiveC)

Swift Compiler - Code Generation

-Onone 일반적인 개발 모드
최소한의 최적화 수행 및 디버그 정보 보존
-O 상용 모드
생성되는 코드의 유형과 양을 크게 변경할 수 있는 적극적인 최적화 수행
디버그 정보는 손실
-Osize 성능보다 코드 크기를 우선시 하는 특수 최적화 모드
-Ounchecked 성능을 위해 안전성을 교환하는 특수 최적화 모드
오버플로/유형 검사 제거 
일반적으로 사용하기 위한 모드는 아님.

 

 

 

 

앱 내 Assertion 사용 시 설정 주의 필요 

Swift 의 경우 

-Onone 의 경우 assertion 이 동작, 

-O, 0Ounchecked 의 경우 assertion 이 동작하지 않음

 

func assert(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line)
  • In playgrounds and -Onone builds (the default for Xcode’s Debug configuration): If condition evaluates to false, stop program execution in a debuggable state after printing message.

  • In -O builds (the default for Xcode’s Release configuration), condition is not evaluated, and there are no effects.

  • In -Ounchecked builds, condition is not evaluated, but the optimizer may assume that it always evaluates to true. Failure to satisfy that assumption is a serious programming error.

 

Objective C 의 경우 

최적화 Level 과 assertion 은 관련이 없음 

 

 

 

 

 

참고

gwangyonglee.tistory.com/50

dmtopolog.com/code-optimization-for-swift-and-objective-c/

stackoverflow.com/questions/57156601/optimization-levels-in-xcode

 

 

 

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함