2017 in Review
Today we’ll take a little holiday break from the C++ Scripting series to look back at 2017 in Unity programming.
Amazingly, the year began way back when Unity 5.5 was the current version. We revisited the performance of various JSON libraries including Unity’s own
JsonUtility. Later in the year we saw just how bloated JSON is and even examined an alternative format in CDB. The takeaway here is that JSON is slow, but we can replace it in many cases and cope with it if we really have to use it in our games.
Elsewhere, there were many articles about the nuts and bolts of C# programming in Unity. We saw how to catch exceptions and use threads with coroutines. We looked at the performance of various types of loops and hash sets and how to get the size of a struct at compile time. Of course this C# is turned into C++ by IL2CPP, so we dove into the C++ that IL2CPP generates and found some surprises. Hopefully this has been both informative and applicable to many Unity projects.
We learned a lot about memory management, too. We took techniques like allocating non-managed memory and applied them to make our own memory allocators and pseudo-pointers. For dealing with the ever-annoying GC, we took a look at how delegates and foreach create garbage as well as some miscellaneous gotchas. We even saw how to avoid the GC when using closures. Avoiding the GC’s wrath remains a critical task with far-reaching implications to our code, so it’s been good to focus on these topics over the year.
A lot of time was also spent on programming techniques. A simple finite state machine (FSM) and formula evaluator were presented in ready-to-use form. In proof-of-concept form, we had a look at an alternative to events, a mechanism for using the Unity API from another thread, and a powerful way to easily generate code. Whether these seemed like good ideas or not, they should have been good food for thought.
Many of these articles have peripherally been about performance, but there was also a series explicitly about that. We learned a bit about how the CPU and memory work so we can best put to use the CPU’s data cache, instruction cache, multiple cores, and SIMD instructions. By designing our data and our code to better match the capabilities of the hardware we can dramatically increase our games’ performance for faster frame rates and more content.
Finally, we started the C++ Scripting series in July with the goal of enabling C++ as an alternative scripting language to C#. We’re now up to 24 articles in the series covering everything from basics like arrays to performance testing to the build system. The GitHub project it spawned has incubated a code generator capable of supporting almost every C# feature out there. We’ll continue the series in the new year and keep on adding functionality toward that goal of making C++ a viable alternative to C# so we can enjoy its many benefits.
Thanks for reading this year and stay tuned for many more articles in 2018!