Alejandro Nunez's showcase is truly smooth.
Developer Alejandro Nunez knows how to make Unity games run well: in a month, he made performance in his large-scale RTS The Last General much smoother, achieving 3 times more FPS than before. Moreover, he shared his ways with other creators.
Using a profiler to identify the worst issues and bottlenecks, he managed to greatly reduce CPU and GPU stress for the game, made with Unity's Entity Component System (ECS) – a data-oriented framework that scales processing performance – and Data-Oriented Technology Stack (DOTS) – a suite of technologies and packages "that deliver a data-oriented design approach to building games."
"One of the greatest wins came from re-batching entities that should be in the same batch, but entities graphics doesn't merge if they are not instantiated at the same time. This reduced batches by about 90%, giving me huge gains both on CPU (dispatching thousands of batches was costly) and GPU, as now there are way fewer commands to execute."
Wakety
To do this, you can either instantiate all the entities at the same time or set the EntitiesGraphicsChunkInfo component of any group of entities to default, which will cause entities graphics to recalculate the batches for those. If you choose the latter, you need to do this for all the entities that you want to put in the same batch in a single frame, Nunez warned.
"For example, you could make a system that grabs all the asteroids in your game (if they should be in the same batch) and switches them all to default EntitiesGraphicsChunkInfo. You will see the number of batches drop drastically. You should check with RenderDoc to see which objects are being placed in separate small batches for no reason, to know which ones need this trick."
Wakety
Another trick is to improve chunk occupancy close to 128 entities per chunk. In some cases, he decided to "split entities into a physics/logic entity and a rendering entity, which allowed better occupancy and unlocked some other optimizations like fully disabling entities rendering in the distance while keeping colliders and other logic active."
Other wins were reordering systems, breaking read/write dependencies between jobs and between systems, unparallelizing short jobs, replacing world space text game objects with Latios Calligraphics texts, and reducing the number of child entities to decrease the time spent on the CalculateHierarchyLocalToWorld job.
Wakety
In addition, compounding static colliders and using the incremental static broadphase feature might help with performance as well, along with "a grid-based sleeping system to turn objects static when nothing is moving in or around a specific cell."
If you want to see how The Last General is developing and get some other tips from Nunez, check out his Reddit profile.
Join our 80 Level Talent platform and our Discord server, follow us on Instagram, Twitter, LinkedIn, Telegram, TikTok, and Threads, where we share breakdowns, the latest news, awesome artworks, and more.