-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Godot 4.1 performs worse than 4.0.3 (get_meta set_meta) #79222
Comments
Your test project has a 3D scene, so FPS is not an accurate measurement for a script performance... |
Yeah, but if you detach the script, do you get the same FPS both in 4.0.3 and 4.1?
No you don't, EDIT: @tool
extends EditorScript
func _run() -> void:
var time = Time.get_ticks_msec()
for i in range(45000):
set_meta("a", 100.0)
set_meta("b", "Barbacue")
set_meta("c", 34)
set_meta("d", 340)
get_meta("a")
get_meta("b")
get_meta("c")
get_meta("d")
print(Time.get_ticks_msec() - time) The times are identical between versions. EDIT2: |
Yes, around 4300 fps for both versions.
Sorry, I misunderstood your suggestion, I wasn't aware of StringNames. If I change the code to:
I get exactly the same frame rates, around 45 fps for 4.03 and around 79 fps for 4.1 |
Try running the code I provided. |
The difference here might be down to that threading changed between 4.0.3 and 4.1, meaning that there's thread guards on But all that aside, this stress tests things far more than could realistically be expected, it's not a real world case |
I increased the iterations to 4500000 to get more consistent results: In 4.0.3 it runs in about 1220ms:
In 4.1 it runs in about 1350ms:
By the way, thanks for the tip, I didn't knew I could run a code that's not attached to a node
I opened this issue because this is a real problem for me. I'm creating a particle system, and I'm using metadata to store information in each particle. And if I have 200 particles in my scene, the code needs to make several metadata operations 200x200 = 40000 times per frame. I'll use C++ later and I see that metadata is slow by itself, but if this performance issue is here to improve multi-threading security I understand. Btw, I know this get's off topic but then, whats the most performant way to save variables to specific objects usign GDscript (like metadata)? |
Since you said you were "stress-testing" I assumed you weren't talking about real-world cases, as they aren't really "stress-testing" I'd say metadata isn't the way to go for that, and that you should use arrays or other storage for that, metadata isn't really intended to be performant AFAIK |
So, I have an array that stores the info for each particle, but how do I link the array index with a specific particle, in other words, how do I know that a specific particle has assigned that specific index in the array? Should I change the particle name to "Pindex" like P0001, P0002, P0003, etc. hmmm, this doesn't look performant. Or maybe I could store each particle in the array itself... |
I'd suggest turning to the other community channels for that |
Note that using a separate node for each particle is already super-inefficient. Instead you could use custom drawing or RenderingServer directly. Then you can represent particles using a simple class that stores any data in plain variables, e.g. class Particle:
var position: Vector
var color: Color
var whatever There's a nice tutorial that explains the concept, it should be possible to apply it in 3D. |
Closing per the above comments. Some low-level functions had to be made slightly slower in 4.1 to allow other methods to be optimized (such as adding/removing a lot of nodes), as well as paving the way for SceneTree multi-threading. In practice, this should allow for a net win in most cases once SceneTree multi-threading is stable. In fact, depending on what your project currently does, the optimizations already in place in 4.1 can be a net improvement. |
Yeah, I tried to put particle logic running in the sub-thread and I got a bit more performance, but not as much as in 4.0.3. But that's because of the poor implementation I currently have as discussed before. Anyway, this opened my mind to implement this in a much faster way, and I'm planning to take advantage of multi-threading. Thank you all again |
Godot version
Godot_v4.1-stable_mono_win64
System information
Windows 10 - Vulkan (Forward+) - RTX 3060 laptop - AMD Ryzen 5 5600H - 24GB RAM
Issue description
Godot 4.1 as a big performance loss when storing metadata in nodes (using set_meta() get_meta()). I made a demo project to test if this was the case, and it looks to be. In 4.0.3 I get around 79 FPS while on 4.1 I get around 45 FPS.
Steps to reproduce
Download the demo file and run it, it's just simple nodes and this code to stress-test the engine:
Minimal reproduction project
Demo project DOWNLOAD:
403vs410.zip
The text was updated successfully, but these errors were encountered: