How the new Data-Oriented Technology Stack delivers major benefits for Tic Toc Games
Tic Toc: A Unity developer case study
How do you speed up development and improve the user experience while adding unprecedented numbers of components to game graphics? Tic Toc Games leveraged Unity’s high-performance Data-Oriented Technology Stack (DOTS) – which includes the Entity Component System (ECS), the C# Job System, and the Burst Compiler – to enable 60 fps performance on mobile devices without draining batteries or overheating phones.
Implement a data-oriented software design approach
Improve multithreading performance and reduce device power requirements
iOS, Android, Xbox One, PS4, Steam, Nintendo Wii U eShop
~40 with 5 developers using Unity
Tic Toc Games is a full-service developer with a seasoned staff of artists, designers, programmers and production managers, all of whom have shipped award-winning interactive products. They want their players to love the game while they are playing, think about it when they are not playing, share their enthusiasm with their friends, and return to play again and again. They’ve used Unity since they began creating games in 2011.
As with any game company, Tic Toc is always looking for ways to get better performance out of its code and, at the same time, iterate faster on design. Garth Smith, Tic Toc’s lead programmer, put it more elegantly: “We need to make better games, faster.” He’s a long-time Unity user, and finds some of the major new features in Unity 2018.x remarkably powerful.
With several high-profile puzzle releases due in 2019, including a Match 3 and a Collapse game, Smith committed his team to leveraging ECS in particular. “Working with ECS, it’s definitely a different way of coding than what people are used to,” Smith noted, “Data-oriented programming is not taught in school much, so it’s a major paradigm shift. Even for us, there was a little bit of fear about starting something new.” However, what they accomplished with ECS made them believers.
- 60 fps on mobile devices without CPUs overheating
- More efficient testing workflow
- Fewer iterations and less troubleshooting/bug-fixing
- Longer device battery life
In order to make massive performance and productivity gains, Tic Toc implemented the major components of Unity’s new Data-Oriented Technology Stack (DOTS), which includes the Entity Component System (ECS), the C# Job System, and the Burst Compiler.
ECS shifts the focus from objects to data
ECS replaces object-oriented coding with a data-oriented approach much more appropriate for many parts of gaming applications. It decouples data from processing, eliminating an enormous amount of data scattering and enables true multithreading as events no longer have to be processed sequentially.
For example, two entities might be a bullet and a player, each with references to different attributes like position, spawning, and health data. The entities and the attributes are pure data with no attached functionality. The system applies a function to an entity, such as a motion system to a bullet or a spawning system to a player. This separation of data and function lets Unity create jobs that can be processed in parallel on multiple cores. According to Mike Geig, Unity’s Global Head of Evangelism Content, “Once it clicks, it’s pretty easy to wrap your head around it.”
The benefits of using ECS are significant. Simply because of the way data is organized, it’s easier to write optimized code – thus the tagline, “Performance by default.” Smith added, “Some of the doors that ECS opened showed us how to make better algorithms.” In addition, ECS code is highly reusable, archetypes (unique entities) are tightly packed in memory, and perhaps most importantly, ECS can take advantage of increasing numbers of CPU cores. Today, mainstream CPUs have up to 4-6 physical and 8-12 logical cores, while “enthusiast” CPUs have up to 16 physical and 32 logical cores. Most go unused, but DOTS takes full advantage of them all.
Watch Mike Geig’s 5-part Intro to the Entity Component System (ECS) and C# Job System.
Teaming up with the C# Job System
Combining the team’s data-oriented ECS code with Unity’s C# Job System let Tic Toc increasingly leverage multi-core processing and multithreading. Writing thread-safe code is difficult because race conditions (threads running in unexpected order, causing unexpected results) add constraints, and constant context-switching is inefficient.
Yet the Job System manages all of the above, letting the Tic Toc developers concentrate on game-specific code. Smith said, “A job lets us run our systems on multiple threads and use different cores on a CPU – processes we found quite difficult to do before. ECS and the Job System let us make almost 100% use of the other cores, which is incredibly efficient.”
The Burst Compiler speaks directly to the hardware
The new Burst Compiler is an LLVM-based, math-aware compiler technology that takes C# jobs and produces highly optimized machine code for the particular capabilities of the target platform. For Tic Toc, that meant Smith and his team didn’t have to spend time relearning and grinding out complex low-level code to fix performance hitches.
“With the Burst Compiler, we could make assumptions about what we’re doing with ECS, and that really sped things up. We found some loops would increase by around 30x, especially when loops occurred many times during a frame,” Smith said.
The team found that when large systems interact, the Burst Compiler eliminates a significant number of integration bugs that would typically have to be weeded out in QA. “With the Burst Compiler, you get the advantages of hand-tuned assembler code, across multiple platforms, without all the hard work,” added Smith.
DOTS advice for other studios
Tic Toc’s transition to a data-oriented approach was tentative at first, but it was a fun challenge to take on. “Once I got the hang of ECS, it started to come along pretty easily. I think at this point, everyone in the studio gets it – we love it, actually – and we’ll probably be doing all our future games with ECS,” said Smith.
He has some solid advice for other studios too. “You don’t have to go ‘all in’ with ECS at first. You can adopt it gradually, and even by doing the small things you’ll get a big performance boost, especially with code reusability.”
As well, Smith recommends doing a prototype project before going into full production. “Try something simple like a game jam, a Tetris, Tic-Tac-Toe – it doesn’t really matter – just complete a game in ECS before you have a whole team go into production with art and all that. You’ll learn a lot with your first exposure to it.”
Finally, Smith is excited about what Tic Toc’s players can expect. “They’re really going to notice the different feel and performance with our new games running at near 60 fps, no matter what’s happening on the screen. I know they’ll definitely appreciate the enhanced gameplay and responsiveness!”
Learn more about DOTS and ECS in these videos: