0 votes

I'm optimizing using servers for a rather simple application of having cells, represented by 3D spheres, simply being born and attracted to each other when they are in close proximity. Either using custom physics or by using Area gravity.

Because I want to have up to thousands of instances, I have read read about optimization here, which promises the following regarding optimization using servers:

"For large amount of instances (in the thousands), that need to be constantly processed (and certain amount of control needs to be retained), using servers directly is the recommended optimization."

Now, I've done that, and I get around 2 FPS already at ~100 instances. This seems to me equivalent to the case when I used scenes. Hence, no qualitative difference in user experience between using servers vs using scenes. And far from the promise of being able to handle thousands of instances.

I'm hoping that the reason is my incompetence. It would be greatly appreciated if you could spot my folly by copying and/or reviewing the code I've pasted here. There are only two scripts: 1) Spatial.gd attached to a main scene with a single Spatial node, and 2) Cell.gd as an unattached script that exist in the FileSystem. It should be trivial to create a new project, add a Spatial node as the main scene with the Spatial.gd attached, and create a new custom script with the code from Cell.gd. Then simply run the project, whereby you will see 125 cells spawned with low FPS. The cells consist of 1) a spherical rigid body, 2) a spherical visual mesh, and 3) a spherical Area that is used to attract other cells through gravity.

What am I doing wrong? What have I misunderstood?

Best regards,

Tobias

in Engine by (140 points)
edited by

There's something off, I can't run your scripts. There is no physics_process for Cell.gd. Also transmission_area is undefined.

Note that using servers directly won't provide an enormous gain, it just removes some overhead, but it's not a lot. I'd expect 20% memory reduction, and eventually 5% speedup (more in other cases not involving GDScript). In addition, if you end up doing more per frame for bookeeping, sometimes it might even be worse due to the overhead of GDScript itself. So depending on what you are doing, using servers directly might not always be the lowest hanging fruit when it comes to speed.

Also, about performance: profile. Find where most of the time is spent first, before doing anything. Did you see where it was?

Also: 125 spherical rigidbodies colliding with each other surely will bring fps down, from what I've seen in the past. They may run fine if they aren't clumped interacting into one place, though.

Consider reducing the detail level for spheres as well, especially if they're displayed from far away.

@omggomb

There's something off, I can't run your scripts. There is no physicsprocess for Cell.gd. Also transmissionarea is undefined.

Damn, sorry. Was apparently a bit sloppy when simplifying the code for demonstration. I've tested the code now and edited the pastelink. It should work now. https://pastebin.com/iVBFehbt

@Zylann, that spells bad news for my project I'm afraid. What takes the most time are the cell functions (not mentioned here), and not the physics, but I can run the cell functions on a longer time scale than the physics, so I considered it worth optimizing.

Also, about performance: profile. Find where most of the time is spent first, before doing anything. Did you see where it was?

Hm... I have not see where most time is spent when it comes to Physics. Do you mean there's a way to find out...?

@Calinoue

Consider reducing the detail level for spheres as well, especially if they're displayed from far away.

Yes, that I will definitely do. I don't need high resolution of the spheres at all.

If you don't need physics simulations to be very accurate and low-latency, you could decrease the physics FPS to 30 in the Project Settings and use lawnjelly's smoothing add-on for interpolation.

@Zylann, I'm using the profiler, and I'm liking it a lot B-). It has lead me to understand that setting the radius of the objects is taking strangely long.

@Calinou, cool with the smoothing add-on! Any ideas on how to implement whilst spawning objects using the Physics and Visual servers directly...?

@toblin I answered to your new question

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.