본문 바로가기
프로그래밍 놀이터/iOS

[ios/reference] Improving Animation Performance

by 돼지왕 왕돼지 2017. 11. 23.
반응형

 [ios/reference] Improving Animation Performance


https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/ImprovingAnimationPerformance/ImprovingAnimationPerformance.html#//apple_ref/doc/uid/TP40004514-CH9-SW1

Alpha channel, animation, async layer rendering, bakcground thread, bitmap image, bitmap image size, Blend, bounds, calayer, CAShapeLayer, contents, CPU, drawing, drawing code, drawlayer, drawrect, drawsasynchronously, floating point number, GPU, incontext, Layer, layer contents, layer size 정수형, opaque layer, Path, property, rendering performance, rendering time, Shadow, shadow path, thread safe, width height 정수형, [ios/reference] Improving Animation Performance, 성능 저하, 성능 측정 테스트


-

가능하면 항상 Opaque Layer 를 사용하라.

     opaque property 를  YES 로 해놓으면 alpha channel 을 유지할 필요가 없음을 알게 된다.

     그래서 blend 하는 로직을 타지 않아도 되서 rendering performance 가 좋아진다.

     만약 contents 에 직접 내용물을 주입하는 경우에는 opaque 값과 상관없이 항상 alpha channel 값이 유지된다.



-

CAShapeLayer 를 사용할 때는 간단한 Path 를 사용하라.

     CAShapeLayer 는 제공한 path 를 bitmap image 로 만든다.

     이 녀석은 장비에 상관없는 drawing 하는 좋은 로직이 있지만, rendering time 은 당연히 늘어난다.

     Path 가 복잡하면 그만큼 성능 저하가 생기고, layer 의 크기가 바뀌어도 다시 그려야 하는 성능 저하가 생긴다.

     단순화하기 어렵다면, 간단한 path 들로 구성된 여러개의 CAShapeLayer 를 만드는 것이 좋다.

     왜냐하면 drawing 은 CPU 에서 이루어지지만 Composing 은 GPU 에서 이뤄지기 때문이다.



-

같은 내용물을 보여주는 Layer 라면 Layer Contents 를 명시적으로 setting 하라.

     여러개의 layer 에 같은 이미지를 표시한다면, image 를 한 번 load 해서 각각의 layer 에 assign 하면 좋다.



-

Layer 의 Size 를 항상 정수형으로 가져가라.

     bounds 를 floating-point number 로 가져가지만, 실제 이 bounds 는 결국 bitmap image size 값으로 사용된다.

     width 와 height 를 정수형으로 가져가면 Core Animation 의 일을 많이 줄여준다. 



-

가능하면 Async Layer Rendering 을 사용하라.

     보통 Layer 의 drawLayer:inContext: 나 View 의 drawRect: 는 sync 로 메인 스레드에서 그린다.

     이것은 성능에 치명적 영향을 끼칠 수 있다. ( 애니메이션을 항상 이렇게 그리면 )

     만약 animation 이 잘 수행되지 않는다면 drawsAsynchronously 속성을 layer 에 지정하여 그리는 동작을 background thread 로 옮길 수 있다.

     물론 drawing code 는 thread safe 해야 한다.

     그리고 또한 물론 asynchronously 설정을 한 후에는 성능 측정을 동반한 테스트를 꼭 해야 한다.



-

Layer 에 Shadow 를 추가할 때는 Shadow Path 를 지정하라.

     Core Animation 에 shadow 의 모양을 결정시키는 것은 매우 비효율적이다.

     shadowPath property 를 CALayer 에 설정하는 것이 효율적이다.

     이렇게 하면 Core Animation 은 shadow effect 를 cache 해서 사용한다.

     layer 의 shape 가 안 바뀌거나 거의 안 바뀌는 경우는 엄청난 성능 향상을 기대할 수 있다.




반응형

댓글