Tag: Performance Optimization

Unity Myth Busters

Unity Myth Buster: GameObject.Transform VS Cached Transform

Caching the transform was one for the first Unity optimizations I ever learned. It was drilled into me like scripture. But things change all the time, and Unity is the fastest evolving software platform I have ever used. Kudos to you Unity! Now I started using Unity back at the end of the 2.x cycle and we have come along way. IL2CPP is freaking amazing. The more profiling I have been doing, the more blown away I am by it. You will clearly see why by the results.

Enough blather, what we are going to be doing here is evaluating our assumption that caching the transform object is faster than referencing it from script or a game object. We are going to be taking our readings from device to be as accurate as possible. In this case, a Samsung Galaxy S8 (Android). I will be providing a link to the evaluation project so please report back with numbers from other platforms if you get different results. Test results from the editor are unreliable and don’t allow you to make use of IL2CPP optimizations.

The Setup

I wanted to check both performance and memory allocation here so I had to do some shenanigans. The most accurate way to get memory allocation readings that I know of is the Unity Profiler. To use that effectively I needed to separate the tests so that I could fire them manually after I had connected the profiler. So I made UI but the Unity canvas and event system creates its own garbage, especially…




Unity Debug Diaries

Performance Myth Busters: Variable Allocation

In Unity Performance Myth Busters I take an assumption and check if it’s still valid or just programming superstition. There is nothing like proof to end an argument or inform a decision. Plus, there is nothing like being humbled by a junior dev because you did not do your homework! Today, I want to chat about local variable usage in an update loop. So, you have all seen a loop like this:

private void Update(){
Vector3 eularRotation = assetToRotate.localEulerAngles;
eularRotation.y += Time.smoothDeltaTime * 10f;
assetToRotate.localEulerAngles = eularRotation;
}

So I created a project to test my theories. I am running on a MacBook Pro, Unity 2017.3.1f1, compiling for Mac standalone. At first, I run it in the editor with the profiler and we are getting the typical GC sawtooth curves. But as we know, profiling in the editor is a lie. Profiling a build, GC is a flat line! No change what so ever. That’s great news but is it only that the change is so tiny, we cant notice? Possible.

Next, I ran 64 instances of my test… and that was a flat line too. Before I bust this myth though, I want to make super sure so we are going to try 100k instances… because I can… and for science. Yea, that was a little heavy-handed. Let’s try 20k.

So after 20k instances of the above code, I can safely say local variable assignments does not generate garbage. Solid like a rock and myth busssssted!

All my Performance…




LA Unity User Group with Zhenping Guo from Unity China

At last night’s Los Angeles Unity User Group, we had the privilege to listen to Zhenping Guo from Unity China. He gave us a great double session, first about performance optimization in Unity and secondly about Unity China and their service offering. Yes, thats right, service offering. Unity is not only committed to making a great tool but its committed to providing ways to bring your creation to the world.. and in this case, that part of the world is China! China’s mobile market is booming and the numbers are staggering in comparison to most other territories. The same goes for Unity. One third of all the unity users in the world are in China and that number is growing rapidly. Why you might ask? Well because of the size of the pie, and Unity is now helping you to get a slice without any cost to you! Thats right, you give em your game, and they do all the work to get it into the Chinese market for a small percentage of profit. I am sure I am simplifying the process but if that at all sounds enticing, make sure to hit Zhenping Guo up for more info.

I also mentioned Text Mesh Pro. For anyone interested in this truly next generation text solution for Unity, check it out here on the Asset Store, or follow Stephan, the author on twitter.

Below are the slides from his great back to back session. If you prefer to download them,…