Nice programing

벡터 렌더링 외에 AS3의 주요 성능 저하 요인은 무엇입니까?

nicepro 2020. 12. 7. 20:41
반응형

벡터 렌더링 외에 AS3의 주요 성능 저하 요인은 무엇입니까?


ActionScript 3에서 벡터 그래픽을 사용하면 프로젝트 성능에 막대한 손상을 입힐 수 있습니다.

모든 벡터 그래픽 대신 개체 Bitmap.copyPixels()통해 모든 그래픽에 단일 사용하면 BitmapData성능이 엄청나게 향상되며 Flash 내에서 게임을 개발하는 저와 같은 사람들에게 필수적입니다.

이 외에는 내가 목표로 삼고 최적화를 시도해야 할 다음 주요 사항이 무엇인지 잘 모르겠습니다. 내장 된 삼각법 함수를 많이 사용하지만 그다지 영향을 미치지 않는 것 같습니다. 근사 방법과 유사한 방법으로 수학을 최적화하는 라이브러리가 있다는 것을 알고 있지만 지금까지 이러한 라이브러리가 필요하다는 것을 알지 못했습니다.

내가 봐야 할 다른 거대한 알려진 포인트가 있습니까? 나는 내 자신의 코딩 스타일을 개선하는 방법보다는 내가 조심해야 할 (벡터 렌더링을 피하는 것과 같은) 내장 된 것들을 더 언급하고있다.


도움이 된 문서는 다음과 같습니다.

몇 가지 하이라이트 :

적절한 표시 개체 선택

메모리 사용을 제한하는 가장 간단한 최적화 팁 중 하나는 적절한 유형의 표시 객체 를 사용하는 입니다. 대화 형이 아닌 단순한 모양의 경우 Shape 개체를 사용하십시오 . 들어 대화 형 객체 타임 라인이 필요하지 않습니다, 사용 스프라이트는 객체. 타임 라인을 사용하는 애니메이션의 경우 MovieClip 객체를 사용 합니다.

사용 getSize()벤치 마크 코드

getSize() 지정된 개체의 메모리 크기를 반환합니다.

메모리를 절약하기 위해 적절한 기본 유형 선택

String을 제외한 모든 기본 유형 은 메모리에서 4-8 바이트를 사용합니다. 번호 가 값이 할당되어 있지 않은 경우에, 64 비트 값을 나타내고, 상기 액션 가상 머신 (AVM)가 8 바이트가 할당된다. 동작은 문자열 유형에 따라 다릅니다. 코드를 벤치마킹하고 작업에 가장 효율적인 개체를 결정합니다.

개체 재사용

개체를 재사용하여 메모리를 최적화하고 가능하면 개체를 다시 만들지 마십시오.

개체 풀링 사용

개체를 재사용하면 개체를 인스턴스화 할 필요가 줄어들어 비용이 많이들 수 있습니다. 또한 가비지 수집기가 실행될 가능성을 줄여 애플리케이션 속도를 저하시킬 수 있습니다.

여유 메모리

객체가 가비지 수집 되었는지 확인하려면 객체에 대한 모든 참조를 삭제합니다. 개체 삭제가 아닌 메모리 할당이 가비지 수집을 트리거합니다. 가능한 한 개체를 재사용하여 가비지 수집 통과를 제한하십시오. 또한 가능한 경우 참조를 null로 설정하여 가비지 수집기가 개체를 찾는 데 더 적은 처리 시간을 소비하도록합니다. 가비지 수집을 보험으로 생각하고 가능하면 항상 객체 수명을 명시 적으로 관리하십시오.

표시 개체에 대한 참조를 null로 설정해도 개체가 고정되지는 않습니다. 개체는 가비지 수집 될 때까지 CPU주기를 계속 사용합니다.

BitmapData 클래스에는 dispose()메서드가 포함되어 있지만 dispose 메서드는 메모리에서 픽셀을 제거하지만 완전히 해제하려면 참조를 null로 설정해야합니다.

비트 맵 사용

특히 많은 수의 벡터를 사용하면 CPU 또는 GPU 리소스에 대한 필요성이 크게 증가합니다. 런타임에서 벡터 콘텐츠를 렌더링하는 것보다 화면에 픽셀을 그리는 데 필요한 처리 리소스가 적기 때문에 비트 맵을 사용 하는 것은 렌더링을 최적화하는 좋은 방법입니다.

Pixel Bender를 통해 처리 된 필터를 포함하여 필터를 피하십시오.

표시 객체에 필터를 적용하면 런타임은 메모리에 두 개의 비트 맵을 만듭니다. 외부에서 제작 된 비트 맵을 사용하면 런타임이 CPU 또는 GPU 부하를 줄이는 데 도움이됩니다.

밉 매핑을 사용하여 큰 이미지 크기 조정

밉 매핑을 아껴 사용하십시오. 축소 된 비트 맵의 ​​품질은 향상되지만 대역폭, 메모리 및 속도에 영향을줍니다.

읽기 전용 텍스트에 텍스트 엔진 사용, TextField입력 텍스트

읽기 전용 텍스트의 경우 메모리 사용량이 적고 렌더링이 더 나은 Flash Text Engine 을 사용하는 것이 가장 좋습니다 . 입력 텍스트의 경우 입력 처리 및 자동 줄 바꿈과 같은 일반적인 비헤이비어를 만드는 데 필요한 ActionScript 코드가 적기 때문에 TextField 객체를 선택하는 것이 좋습니다.

이벤트 대신 콜백 사용

네이티브 이벤트 모델을 사용하면 기존 콜백 함수를 사용하는 것보다 더 느리고 더 많은 메모리를 사용할 수 있습니다. 이벤트 개체를 만들고 메모리에 할당해야 성능이 저하됩니다. 예를 들어 Event.ENTER_FRAME이벤트를 수신 할 때 이벤트 핸들러의 각 프레임에 새 이벤트 객체가 생성됩니다. 캡처 및 버블 링 단계로 인해 표시 개체의 성능이 특히 느려질 수 있으며 표시 목록이 복잡한 경우 비용이 많이들 수 있습니다.

스테이지에서 추가 / 제거 된 개체 고정 및 고정 해제

표시 객체가 더 이상 표시 목록에없고 가비지 수집을 기다리고있는 경우에도 여전히 CPU 집약적 인 코드를 사용할 수 있습니다.

고정 개념은 Loader 클래스를 사용하여 원격 콘텐츠를로드 할 때도 중요합니다.

unloadAndStop() 메서드를 사용하면 SWF 파일을 언로드하고로드 된 SWF 파일의 모든 객체를 자동으로 고정하고 가비지 수집기를 강제로 실행할 수 있습니다.

백그라운드 비활성 감지를위한 사용 Event.ACTIVATEEvent.DEACTIVATE이벤트

Event.ACTIVATEEvent.DEACTIVATE이벤트를 사용하면 런타임이 포커스를 얻거나 잃을 때를 감지 할 수 있습니다. 결과적으로 컨텍스트 변경에 대응하도록 코드를 최적화 할 수 있습니다.

활성화 및 비활성화 이벤트를 사용하면 모바일 장치 및 넷북에서 가끔 볼 수있는 "일시 중지 및 다시 시작"기능과 유사한 메커니즘을 구현할 수 있습니다.

가능한 경우 마우스 상호 작용 비활성화

많은 대화 형 개체가 화면에 표시 될 때, 특히 겹치는 경우 마우스 상호 작용을 감지하는 것은 CPU를 많이 사용할 수 있습니다. 가능하면 마우스 상호 작용을 비활성화하여 응용 프로그램이 CPU 처리를 덜 사용하도록하여 결과적으로 모바일 장치의 배터리 사용량을 줄이는 것이 좋습니다.

애니메이션이 아닌 콘텐츠에 타이머 사용

Event.ENTER_FRAME장시간 실행되는 애니메이션이 아닌 콘텐츠의 이벤트 보다 타이머가 선호 됩니다.

타이머는 Event.ENTER_FRAME이벤트 와 유사한 방식으로 작동 할 수 있지만 프레임 속도에 연결되지 않고 이벤트를 전달할 수 있습니다. 이 동작은 몇 가지 중요한 최적화를 제공 할 수 있습니다. 비디오 플레이어 애플리케이션을 예로 들어 보겠습니다. 이 경우 응용 프로그램 컨트롤 만 움직이기 때문에 높은 프레임 속도를 사용할 필요가 없습니다.

트위닝 제한

트위닝 사용을 제한하면 CPU 처리, 메모리 및 배터리 수명이 절약되어 콘텐츠가 하위 계층 장치에서 더 빠르게 실행됩니다.

사용 Vectorvs.Array

벡터 클래스는 빠르게 읽고보다 쓰기 액세스 할 수 있습니다 배열 클래스입니다.

Vector 인스턴스를 사용하면 Array를 사용할 때보 다 배열 요소 액세스 및 반복이 훨씬 빠릅니다.

엄격 모드에서 컴파일러는 데이터 유형 오류를 식별 할 수 있습니다.

런타임 범위 검사 (또는 고정 길이 검사)는 어레이보다 안정성을 크게 향상시킵니다.

더 빠른 코드 실행을 위해 그리기 API 사용

사용하여 코드 실행의 양을 줄이고 drawPath(), drawGraphicsData(), drawTriangles()코드 줄이 감소되면 ActionScript 실행 성능을 제공 할 수 있습니다.

이벤트 캡처 및 버블 링을 사용하여 이벤트 핸들러 최소화

이벤트 버블 링을 활용하면 ActionScript 코드 실행 시간을 최적화하는 데 도움이 될 수 있습니다. 성능 향상을 위해 여러 개체 대신 하나의 개체에 이벤트 처리기를 등록 할 수 있습니다.

setVector()방법을 사용하여 픽셀 페인트

픽셀을 그릴 때 BitmapData 클래스의 적절한 메서드를 사용하여 몇 가지 간단한 최적화를 수행 할 수 있습니다. 픽셀을 그리는 빠른 방법은 setVector()방법 을 사용하는 것입니다.

lock()unlock() BitmapData같은 느린 방법을 사용하는 경우 setPixel()또는setPixel32()

Calling lock() and unlock() prevents the screen from being updated unnecessarily. Methods that iterate over pixels, such as getPixel(), getPixel32(), setPixel(), and setPixel32(), are likely to be slow, especially on mobile devices. If possible, use methods that retrieve all the pixels in one call. For reading pixels, use the getVector() method, which is faster than the getPixels() method. Also, remember to use APIs that rely on Vector objects, when possible, as they are likely to run faster.

Use String class methods instead of regular expressions

When a String class method is available, it runs faster than the equivalent regular expression and does not require the creation of another object.

For TextFields, use apendText() instead of the += operator

appendText()방법을 사용하면 성능이 향상됩니다.

대괄호 연산자 []는 성능을 저하시킬 수 있습니다. 로컬 변수에 참조 저장

대괄호 연산자를 사용하면 성능이 저하 될 수 있습니다. 참조를 지역 변수에 저장하여 사용을 피할 수 있습니다.

코드를 인라인으로 이동하여 함수 호출 수 감소

함수 호출은 비용이 많이들 수 있습니다. 코드를 인라인으로 이동하여 함수 호출 수를 줄이십시오.

함수 호출을 인라인으로 이동하면 코드가 4 배 이상 빨라집니다.

무대 밖에서 콘텐츠를 배치하지 마십시오.

오프 스테이지 요소가 화면에 표시되지 않고 렌더링되지 않더라도 디스플레이 목록에는 여전히 존재합니다. 런타임은 이러한 요소에 대해 내부 테스트를 계속 실행하여 여전히 오프 스테이지 상태이고 사용자가 요소와 상호 작용하지 않는지 확인합니다.

Avoid using alpha property

When a display object uses alpha blending, the runtime must combine the color values of every stacked display object and the background color to determine the final color. Thus, alpha blending can be more processor-intensive than drawing an opaque color. This extra computation can hurt performance on slow devices.

Use lowest possible frame rate

A higher frame rate expends more CPU cycles and energy from the battery than a lower rate.

Runtime code execution fundamentals elastic-racetrack

Use bitmap caching for complex vector content

This feature caches a vector object, renders it as a bitmap internally, and uses that bitmap for rendering. Bitmap caching improves rendering if the cached content is not rotated, scaled, or changed on each frame. Any transformation other than translation on the x- and y-axes, rendering is not improved.

Set cacheAsBitmapMatrix property when using cached bitmaps in mobile AIR apps

cacheAsBitmapMatrix in the AIR mobile profile you can apply any two-dimensional transformation to the object without regenerating the cached bitmap. You can also change the alpha property without regenerating the cached bitmap.

Use BitmapData class to create custom bitmap caching behavior

Using only a single cached bitmap is used in memory and shared by all instances.

Isolate events such as Event.ENTER_FRAME in a single handler

This technique saves CPU resources.

Use the bitmap caching feature and the opaqueBackground property to improve text rendering performance

The bitmap caching feature allows you to cache vector content as bitmaps to improve rendering performance. This feature is helpful for complex vector content and also when used with text content that requires processing to be rendered.

Alpha transparency places an additional burden on the runtime when drawing transparent bitmap images. You can use the opaqueBackground property to bypass that, by specifying a color as a background.

Enable GPU hardware graphics acceleration

In order to leverage GPU acceleration of Flash content with AIR for mobile platforms, Adobe recommends that you use renderMode="direct" (that is, Stage3D) rather than renderMode="gpu". Adobe officially supports and recommends the following Stage3D based frameworks: Starling (2D) and Away3D (3D).

Avoid using wmode=transparent or wmode=opaque in HTML embed parameters. These modes can result in decreased performance. They can also result in a small loss in audio-video synchronization in both software and hardware rendering. Furthermore, many platforms do not support GPU rendering when these modes are in effect, significantly impairing performance.

Favor using asynchronous versions of operations

Application code in the current execution thread continues executing.

Asynchronous operations are scheduled and divided to avoid rendering issues. Consequently, it is much easier to have a responsive application using asynchronous versions of operations. See Perceived performance versus actual performance for more information.

Smooth shapes to improve rendering

Unlike bitmaps, rendering vector content requires many calculations, especially for gradients and complex paths that contain many control points. As a designer or developer, make sure that shapes are optimized enough.

Cache assets locally after loading them, instead of loading them from the network each time they're needed

If your application loads assets such as media or data, cache the assets by saving them to the local device. For assets that change infrequently, consider updating the cache at intervals.

Use the StageVideo class to take advantage of hardware acceleration

Use the StageVideo class to take advantage of hardware acceleration to present video.

This approach takes full advantage of the underlying video hardware. The result is a much lower load on the CPU, which translates into higher frame rates on less powerful devices and also less memory usage.

The AAC audio format offers better quality and smaller file size than the mp3 format at an equivalent bit rate

Similar to video decoding, audio decoding requires high CPU cycles and can be optimized by leveraging available hardware on the device.

The AAC format offers better quality and smaller file size than the mp3 format at an equivalent bitrate.

Minimize code in constructors

Initialization function such as constructors are interpreted, everything else is JIT.

참고URL : https://stackoverflow.com/questions/8380789/what-are-the-major-performance-hitters-in-as3-aside-from-rendering-vectors

반응형