Special optimizations Flashcards

1
Q

Multidimensional vs. jagged arrays

A

One-Dimensional Array 660 ms
Jagged Arrays 730 ms
Multidimensional Array 3470 ms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Particle System pooling

A

When pooling Particle Systems
, be aware that they consume at least 3500 bytes of memory. This memory is not released when Particle Systems are deactivated; It is only released when they are destroyed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Using C# delegates in an update manager

A

It is tempting to use plain C# delegates to implement these callbacks. However, C#’s delegate implementation is optimized for a low rate of subscription and unsubscription, and for a low number of callbacks. A C# delegate performs a full deep-copy of the callback list each time a callback is added or removed. Large lists of callbacks, or large numbers of callbacks subscribing/unsubscribing during a single frame results in a performance spike in the internal Delegate.Combine method.

For cases where adds/removes occur at high frequencies, consider using a data structure designed for fast inserts/removes instead of delegates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Loading thread control

A

Resources.LoadAsync and AssetBundle.LoadAssetAsync are operated by Unity’s internal PreloadManager system, which governs its own loading thread(s) and performs its own rate-limiting. UnityWebRequest uses its own dedicated thread pool. WWW spawns an entirely new thread each time a request is created.

While all other loading mechanisms have a built-in queuing system, WWW does not. Calling WWW.LoadFromCacheOrDownload on a very large number of compressed AssetBundles spawns an equivalent number of threads, which then compete with the main thread for CPU time. This can easily result in frame-rate stuttering.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Trivial properties

A

Because every reference to a const variable is replaced with its value, it is inadvisable to declare long strings or other large data types const. This unnecessarily bloats the size of the final binary due to all the duplicated data in the final instruction code.

Wherever const isn’t appropriate, make a static readonly variable instead. In some projects, even Unity’s built-in trivial properties have been replaced with static readonly variables, resulting in small improvements in performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Trivial methods

A

Trivial methods are trickier. It is extremely useful to be able to declare functionality once and reuse it elsewhere. However, in tight inner loops, it may be necessary to depart from good coding practices and instead “manually inline” certain code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly