# Increasing game performance

**URL:** <https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841>\
**Category:** Programming\
**Created:** [December 12, 2021, 2:46pm UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841 "2021-12-12T14:46:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![hhyyrylainen](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/hhyyrylainen/32/2243_2.png) [@hhyyrylainen](https://forum.revolutionarygamesstudio.com/u/hhyyrylainen)\
**Post date:** [December 12, 2021, 2:46pm UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/1 "2021-12-12T14:46:14Z")

</div>

Let’s get some information down on the dev forums as well about low performance.

So the game seems to drop to low FPS after playing for quite a while. Even dropping to single digit FPS. I’ve already reduced the game entity limit from 1000 to 300, but even that doesn’t fully help, but seem to at least postpone the problem a bit.

I’ve done C# profiling:

 ![Kuvakaappaus - 2021-12-05 10-42-11](https://thrivedevforum-uploads.b-cdn.net/original/2X/d/d04fa015da9a7a65bc0ec52c23e29cf76302369a.png)

 ![Kuvakaappaus - 2021-12-05 10-46-30](https://thrivedevforum-uploads.b-cdn.net/original/2X/4/46d0e3a9fd8da5cd2b9bf6861788737f3736a9f8.png)

And native code profiling:

[![](https://cdn.discordapp.com/attachments/464846875187478548/916995043154329600/output.png) ](https://cdn.discordapp.com/attachments/464846875187478548/916995043154329600/output.png)

Here’s the raw numbers: [https://cdn.discordapp.com/attachments/464846875187478548/916996100198629386/out.zip](https://cdn.discordapp.com/attachments/464846875187478548/916996100198629386/out.zip)

I wrote some instructions on profiling here: [Thrive/profiling.md at master · Revolutionary-Games/Thrive · GitHub](https://github.com/Revolutionary-Games/Thrive/blob/master/doc/profiling.md)

Note that you should disable auto-evo in background and set worker threads to 1 in options to get cleaner profiling numbers.

I’ve tried disabling AI, rendering microbe graphics other than the player, and disabling microbe sound. Those have no impact on the performance. It seems that around 30% of total time is taken up by physics and Godot scene tree updates, with 10% being our C# physics callbacks. So yeah I don’t have any easy ideas at this point other than further restricting the number of game entities.

---

<div class="post-metadata">

**Author:** ![Nunz](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/nunz/32/1505_2.png) [@Nunz](https://forum.revolutionarygamesstudio.com/u/Nunz)\
**Post date:** [December 12, 2021, 4:24pm UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/2 "2021-12-12T16:24:18Z")

</div>

Other than reducing the number of entities I can only think of using Godot’s Servers: [Optimization using Servers — Godot Engine (stable) documentation in English](https://docs.godotengine.org/en/stable/tutorials/optimization/using_servers.html)

---

<div class="post-metadata">

**Author:** ![RacerBG](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/racerbg/32/1862_2.png) [@RacerBG](https://forum.revolutionarygamesstudio.com/u/RacerBG)\
**Post date:** [December 12, 2021, 9:29pm UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/3 "2021-12-12T21:29:56Z")

</div>

While I can’t make a fancy graph like this I could provide you with a rough estimate of the perfomance of Thrive on my system:

**PC Configuration:**  
RAM: 16 GB DDR3  
CPU: AMD FX-8320  
GPU: AMD Radeon R7 250 2GB VRAM (Display Resolution: 1920x1080)

**Thrive Settings:**  
Version: 0.5.6.1  
FPS Limit: 120  
Vsync: OFF  
MSAA: Disabled  
Clouds simulation: 250 ms  
Auto-Evo during gameplay: OFF  
Used Threads: 8

**Benchmarks:**

Main Menu and Patch Map Perfomance: 120 (usually it is around 211 FPS)

 ![2021-12-12_22.59.59.4231](https://thrivedevforum-uploads.b-cdn.net/original/2X/2/20c82d78b7e8d9931ccb4955a62d4fc620e36ece.jpeg)

Auto-Evo Report: around 100 FPS probably due to the graphs

 ![2021-12-12_23.00.10.4657](https://thrivedevforum-uploads.b-cdn.net/original/2X/e/ef8f58da678ac39f433ee0f41d922d7d51616965.jpeg)

Editor: around 90 FPS

 ![2021-12-12_22.59.29.3394](https://thrivedevforum-uploads.b-cdn.net/original/2X/a/abfbd4320f048704c35244822e87ceed26b8c564.jpeg)

Membrane Tab: between 60-70 FPS

 ![2021-12-12_22.59.36.5148](https://thrivedevforum-uploads.b-cdn.net/original/2X/1/104dd2832fe3aa29c25ae77366a1d0284f623a52.jpeg)

During gameplay for the current save the FPS is around 2-12. The save is created in Freebuild Mode and it’s on generation 16. I managed to increase the perfomance (probably) due to 5 or 6 extinctions which I managed to create in my patch. Currently it have 10 species with various populations (including mine of course) and the FPS is back to around 30-40.

And here are a few of the things which I wrote in Discord earlier today, I will just leave them as a quote:

> I’m starting to get suspicious what causes the game lagging so much because the moment when I’m either saving or waiting for the auto-evo to finish, my FPS goes from 3-7 at generation 16 with a freebuild cell to 50-80:
> 
> 1. The rendering of the clouds probably have an good impact but does it really? At the beginning of the game you can easily see a lot of clouds and my FPS won’t drop so dramatically (49-to FPS at the lowest).
> 2. The number of objects around me is probably way more FPS intensive and causes spikes and FPS drops but still around my cell the objects shouldn’t be over 20-30 at best. But then it came to my mind that every cell have 3D objects in it and the tip of he iceberg is that they (the organelles) are animated as well.  
> 2.1. Does Thrive uses occlusion culling? This should solve most of the problems in my opinion?  
> 2.2 Could we add an option to the Perfomance tab which disables the organelle animations?  
> 2.3 When zooming out there is no point in animating the internal cell organelles anyway. If the animations are automatically disabled at a certain zoom level this would help for the perfomance of the game.

---

<div class="post-metadata">

**Author:** ![Nunz](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/nunz/32/1505_2.png) [@Nunz](https://forum.revolutionarygamesstudio.com/u/Nunz)\
**Post date:** [December 13, 2021, 3:32am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/4 "2021-12-13T03:32:42Z")

</div>

For the occlusion culling, Godot does not support that feature like other engines. The organelles shader could indeed be made much more performative.

---

<div class="post-metadata">

**Author:** ![hhyyrylainen](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/hhyyrylainen/32/2243_2.png) [@hhyyrylainen](https://forum.revolutionarygamesstudio.com/u/hhyyrylainen)\
**Post date:** [December 13, 2021, 11:25am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/5 "2021-12-13T11:25:09Z")

</div>

I don’t think we use ambient occlusion, if you are talking about the render effect.  
From my profiling results it doesn’t seem like that sending rendering commands to the GPU is the bottleneck, nor is waiting for GPU to process the current frame.

---

<div class="post-metadata">

**Author:** ![Nunz](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/nunz/32/1505_2.png) [@Nunz](https://forum.revolutionarygamesstudio.com/u/Nunz)\
**Post date:** [December 13, 2021, 7:40pm UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/6 "2021-12-13T19:40:18Z")

</div>

I meant occlusion culling, my bad. It’s an important method for really weak or older gpu but as you say, rendering isn’t the bottleneck.

---

<div class="post-metadata">

**Author:** ![hhyyrylainen](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/hhyyrylainen/32/2243_2.png) [@hhyyrylainen](https://forum.revolutionarygamesstudio.com/u/hhyyrylainen)\
**Post date:** [July 20, 2022, 5:26pm UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/7 "2022-07-20T17:26:07Z")

</div>

I wrote about ways we could alternatively get around the performance problems, but these ideas are very hard and time consuming to implement:

> [@Alternative ways to fix the performance](https://forum.revolutionarygamesstudio.com/t/alternative-ways-to-fix-the-performance/907):
>
> I’ve tried to profile the game to look for places to improve the performance ([Increasing game performance](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841)) and I’ve managed to do some things by adding multithreading for part of the microbe operations etc., it’s still not exactly good. And we had to put in the entity limit into the game, which can be lowered to a pretty ridiculously low number. And even then the normal value isn’t exactly a good performance even on a fast system. With me pretty much out of ideas having tested disabling various …

---

<div class="post-metadata">

**Author:** ![NickTheNick](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/nickthenick/32/17_2.png) [@NickTheNick](https://forum.revolutionarygamesstudio.com/u/NickTheNick)\
**Post date:** [July 23, 2022, 1:18am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/8 "2022-07-23T01:18:15Z")

</div>

Just spitballing here, would it be that bad to place an upper limit on the number of species that can spawn per patch?

I wonder how much extra benefit the gameplay receives if instead of 8 species in a patch you have 10, or 12, or more. Plus, we could introduce mechanics to cull underperforming species to free up “slots” for new species to diverge.

---

<div class="post-metadata">

**Author:** ![hhyyrylainen](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/hhyyrylainen/32/2243_2.png) [@hhyyrylainen](https://forum.revolutionarygamesstudio.com/u/hhyyrylainen)\
**Post date:** [July 23, 2022, 11:02am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/9 "2022-07-23T11:02:43Z")

</div>

We now have an entity cap for how much stuff can spawn in general, and it can be cranked way down. Spawning depends on population so we should still get a somewhat good representation even with the tiniest limit of all species in the patch. I see limiting the number of species as a cruder alternative as their populations could get very high and spawn a ton of stuff if there is no global limit. And we already basically have species limiting per patch as in auto-evo adds huge penalties to species to keep the count from going above a configured limit (I think it’s maybe 10 or 12 currently).

---

<div class="post-metadata">

**Author:** ![Oliveriver](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/oliveriver/32/1962_2.png) [@Oliveriver](https://forum.revolutionarygamesstudio.com/u/Oliveriver)\
**Post date:** [July 23, 2022, 4:41pm UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/10 "2022-07-23T16:41:33Z")

</div>

Another spitball idea I had related to this:

It’s clear that bigger cells cause more performance issues, purely because they have more going on (more nodes, more compound processing, etc.). Currently though big cells count for exactly the same as small cells as far as the entity limit is concerned. Could we have some kind of weighting so that the bigger the cell, the more “entities” it represents? Obviously we’d have to change the nomenclature, and this will have severe gameplay implications since fewer big cells will spawn. I can also forsee a few other issues, such as the game refusing to spawn any cells at all if the entity cap is set at tiny but all possible species are too big. But I think it’s worth an investigation at least to see how it affects performance.

---

<div class="post-metadata">

**Author:** ![hhyyrylainen](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/hhyyrylainen/32/2243_2.png) [@hhyyrylainen](https://forum.revolutionarygamesstudio.com/u/hhyyrylainen)\
**Post date:** [July 23, 2022, 5:16pm UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/11 "2022-07-23T17:16:53Z")

</div>

That’s certainly possible. Calling the option still “entity limit” makes sense as different kind of entities naturally have different performance impacts, so not having a direct 1-to-1 impact on some specific entity type is not a problem.

There’s already an issue open about making cells in colonies count differently (though I’m not a bit unsure if it should be a discount or actually a penalty):

> <https://github.com/Revolutionary-Games/Thrive/issues/3208>
>
> I recently realized that the spawn system was trying to despawn colony members. …This means that the way it counts the nodes in the scene tree it will also detect colony members as microbes. This means that just a couple of really big colonies will eat up the entity limit entirely. To combat this I think we should optimally change the spawn system so that only the top level Nodes count in the limit (and are subject to despawning).

If I remember right the spawn system, spawns stuff if the limit is not reached, so a single spawn is allowed to go over the limit, but then it should prevent entities from spawning (with the caveat that there currently seems to be a bug with this).

---

<div class="post-metadata">

**Author:** ![Kasterisk](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/kasterisk/32/2621_2.png) [@Kasterisk](https://forum.revolutionarygamesstudio.com/u/Kasterisk)\
**Post date:** [July 25, 2022, 10:16am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/12 "2022-07-25T10:16:26Z")

</div>

The entity limit seems to be the most critical to performance, due to this I’m confident we should also add this option to the new game settings up front. An accompanying tooltip or text should then let the player know about its benefit.

---

<div class="post-metadata">

**Author:** ![Oliveriver](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/oliveriver/32/1962_2.png) [@Oliveriver](https://forum.revolutionarygamesstudio.com/u/Oliveriver)\
**Post date:** [July 25, 2022, 10:40am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/13 "2022-07-25T10:40:24Z")

</div>

I don’t think it should be part of the new game settings, since it’s nothing to do with the world of a specific game and is instead relevant across multiple games, and can even be changed partway through a game. But I agree it needs to be more prominent at the start of a game. Maybe a pop up when opening the main menu for the first time prompting the player to visit the options menu to set it?

---

<div class="post-metadata">

**Author:** ![Kasterisk](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/kasterisk/32/2621_2.png) [@Kasterisk](https://forum.revolutionarygamesstudio.com/u/Kasterisk)\
**Post date:** [July 25, 2022, 11:00am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/14 "2022-07-25T11:00:41Z")

</div>

It’s just a matter of discoverability and I feel it’s is the most intuitive. This will be like those options in games where you can set them in the new game setup but also tells you that they can be changed later whenever. Having a pop up in the main menu can probably be jarring in my opinion.

---

<div class="post-metadata">

**Author:** ![hhyyrylainen](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/hhyyrylainen/32/2243_2.png) [@hhyyrylainen](https://forum.revolutionarygamesstudio.com/u/hhyyrylainen)\
**Post date:** [August 21, 2022, 8:43am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/15 "2022-08-21T08:43:21Z")

</div>

I disabled organelle graphics. It only gave me an extra 10 FPS in this save (by lowering the number of draw calls by about 800 per frame):

 ![2022-08-21_11.38.23.4747](https://thrivedevforum-uploads.b-cdn.net/original/2X/7/74203fe912f723a86d977fe2b306578465cbd1eb.jpeg)

 ![2022-08-21_11.38.37.6844](https://thrivedevforum-uploads.b-cdn.net/original/2X/8/8d08c5c9b6d0191422dbe1e6b2047e4931183c53.jpeg)

So while rendering a bunch of individual (transparent) organelles does impact performance, removing that entirely does not fix the performance.

So Godot needing to sort and issue draw calls for the individual organelles doesn’t seem to be our biggest performance problem.

One other potential thing people [said](https://www.reddit.com/r/godot/comments/wrtgvp/looking_for_help_with_performance_3d_godot_scene/) is that we should try to do something about the fact that each individual organelle is a sphere collision that is added to the overall shape of a cell. Basically what we could do is generate a mesh collision from the organelles and use just 2 shapes one for general and one for pilus collisions (or maybe keeping pilus collisions as is would be easier and not impact performance that much).

---

<div class="post-metadata">

**Author:** ![Kasterisk](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/kasterisk/32/2621_2.png) [@Kasterisk](https://forum.revolutionarygamesstudio.com/u/Kasterisk)\
**Post date:** [August 22, 2022, 3:15am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/16 "2022-08-22T03:15:29Z")

</div>

> [@hhyyrylainen](#):
>
> So Godot needing to sort and issue draw calls for the individual organelles doesn’t seem to be our biggest performance problem.

But I think it does add up so if we were to apply different combination of optimizations: multimesh + frustum culling + entity limit + reducing collision shapes + etc, etc. That would potentially give 20 or 30+ FPS increase which honestly doesn’t seem bad.

> [@hhyyrylainen](#):
>
> Basically what we could do is generate a mesh collision from the organelles and use just 2 shapes one for general and one for pilus collisions

Previously in my engulfment revamp PR I made it possible to form a convex collision shape from the shape of the membrane, I think the code is still in the membrane code so it probably can be useful for this.

---

<div class="post-metadata">

**Author:** ![NickTheNick](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/nickthenick/32/17_2.png) [@NickTheNick](https://forum.revolutionarygamesstudio.com/u/NickTheNick)\
**Post date:** [August 24, 2022, 7:15pm UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/17 "2022-08-24T19:15:07Z")

</div>

I think it would be definitely worthwhile to combine a set of several optimizations if together they produce a significant improvement in framerate. We only need to keep performance good until the end of the Microbe Stage, after which metaballs will be able to handle performance much better.

Was also thinking… I know it would be a painful decision, but do we need the reproduction system as it currently stands? Where every organelle is one by one split until you reproduce? If it takes a lot of computational power to constantly recalculate the size of cells, couldn’t we switch over to a system where cells simply acquire the required nutrients, and then once they have enough they duplicate all their organelles at once? It would mean only one calculation at the end of a cell’s life cycle, instead of constant recalculations every time he absorbs more nutrients.

---

<div class="post-metadata">

**Author:** ![Buckly](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/buckly/32/1259_2.png) [@Buckly](https://forum.revolutionarygamesstudio.com/u/Buckly)\
**Post date:** [August 25, 2022, 2:28am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/18 "2022-08-25T02:28:09Z")

</div>

It may not seem like much, but just 10 fps can make a world of a difference if you have particularly low framerates. Imagine running the game steadily at 20 fps; This change would bump you up to 30 or maybe more, making the game go from a slideshow to atleast bearable! 30 fps used to be industry standard you know.

As everyone else has said, every little bit can help.

---

<div class="post-metadata">

**Author:** ![Gamedungeon](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/gamedungeon/32/2202_2.png) [@Gamedungeon](https://forum.revolutionarygamesstudio.com/u/Gamedungeon)\
**Post date:** [August 25, 2022, 2:33am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/19 "2022-08-25T02:33:15Z")

</div>

Does that system even have an effect on gameplay? Everything should even out, except maybe cell speed.

---

<div class="post-metadata">

**Author:** ![hhyyrylainen](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/hhyyrylainen/32/2243_2.png) [@hhyyrylainen](https://forum.revolutionarygamesstudio.com/u/hhyyrylainen)\
**Post date:** [August 25, 2022, 6:57am UTC](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841/20 "2022-08-25T06:57:37Z")

</div>

> [@NickTheNick](#):
>
> If it takes a lot of computational power to constantly recalculate the size of cells

It doesn’t take very long to simulate a new membrane shape currently. Only reason organelle splitting causes lag spikes is due to this issue:

> <https://github.com/Revolutionary-Games/Thrive/issues/3273>
>
> probably caused by the approach of starting at 0,0 coordinates and spiraling out…wards until an empty spot is found. That probably starts running quite long when the cell is very large in radius.
> 
> I think we have two choices to fix this:
> \- Have the algorithm remember where it last placed an organelle and look for free spots nearby to cut down on the attempts it needs before finding a spot
> \- Run the search in a background task (TaskExecutor) and then place the duplicate organelle once the task is complete and it has found a suitable position

Though, this’ll be an entirely different matter when we eventually get 3D membranes with much more expensive computations required.

Also there’s a membrane data caching feature now so each time a membrane is generated, the membrane is stored and can be loaded later. If we don’t care about extra memory use the membrane cache time can be increased to make all intermediate reproduction steps be found in the cache.

> [@Buckly](#):
>
> It may not seem like much, but just 10 fps can make a world of a difference if you have particularly low framerates. Imagine running the game steadily at 20 fps; This change would bump you up to 30 or maybe more, making the game go from a slideshow to atleast bearable! 30 fps used to be industry standard you know.

I suppose this is a fair point, but the reason why I’m chasing really large improvements is because these kind of small things will at most allow the game to have like 10 more cells in the game at once, so the performance gain that allows 80 cells instead of 70 seems actually pretty insignificant to me…

> [@Gamedungeon](#):
>
> Does that system even have an effect on gameplay? Everything should even out, except maybe cell speed.

Yes. Currently the player has to survive on a partially duplicated cell. Switching to all duplication happening at once, basically needs to be made into a reproduction animation that is just played out instead of doing the current operations all at once (as _that_ would cause big lag spikes if it all happens very quickly).

[Next page](https://forum.revolutionarygamesstudio.com/t/increasing-game-performance/841.md?page=2)
