Skip to content
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

Many static bodies cause severe slowdowns #1033

Closed
wagnerfs opened this issue Dec 20, 2024 · 5 comments
Closed

Many static bodies cause severe slowdowns #1033

wagnerfs opened this issue Dec 20, 2024 · 5 comments
Labels
performance Something isn't as fast as it probably could be topic:runtime Concerning runtime behavior (or its source code) wontfix This will not be worked on

Comments

@wagnerfs
Copy link

wagnerfs commented Dec 20, 2024

This is a weird one, I've got over 400k+ bodies in a scene (procedurally created) but with its collision disabled, I only enable a few of them close to the player, with the built in Godot engine this works super fine, no performance hit or anything.

With jolt on the other hand, the first problem I encounter is the max_bodies that needs to be raised considerably for things to even work, but even though I'd say 90% of those bodies are disabled, I'm still getting such a heavy performance hit, so I assume they're still getting tested even when they got all their collision shape disabled?

Example project:
custom-4.4-test.zip

@github-actions github-actions bot added the needs triage Something that needs investigation label Dec 20, 2024
@mihe mihe added topic:runtime Concerning runtime behavior (or its source code) performance Something isn't as fast as it probably could be and removed needs triage Something that needs investigation labels Dec 20, 2024
@mihe
Copy link
Contributor

mihe commented Dec 20, 2024

How are you creating the bodies, and how are you disabling their collision?

There is currently a tiny amount of overhead during the physics step that apply to any body that's added to a physics space (i.e. a scene tree), which stems from me iterating over every one of them regardless of their sleep state. That will almost certainly become quite significant when dealing with hundreds of thousands of bodies.

Jolt does offer the ability to iterate over only active/awake bodies, which I did make use of for a brief time, but it led to state desynchronization issues that were tricky to solve, hence the current heavy-handed solution.

I've been meaning to look into solving this for the new engine module in Godot 4.4, but it's unclear whether I'll address it in this extension, since it's not strictly a bug per se.

Anyway, if you could share some kind of representative minimal repro of your issue I'd appreciate it, so that I can know whether we're talking about the same problem.

@wagnerfs
Copy link
Author

I'll try to put up something this week, I only currently tested it in a game I've been working on which's a procedural world.

@wagnerfs
Copy link
Author

alright, I made a small project with 4 buttons where you can create 200k objects, each button adds them in a thread or on the main thread, one adds phyiscs objects that get their collision shape disabled when they're added to the scene and the other just empty meshes for comparison.

I set the project max_bodies value to default * 512, but the FPS drops extremely fast even before the 100k objects mark.
Just in case I'm uploading the file here and in my OG post.

custom-4.4-test.zip

@mihe
Copy link
Contributor

mihe commented Dec 28, 2024

Thank you! I'll take a look at it some time later next week.

@mihe
Copy link
Contributor

mihe commented Dec 31, 2024

I've put up a pull request in the Godot repo that seems to resolve this issue: godotengine/godot#100983

I'm not super keen on backporting this change to the extension at the moment, so I think I'll leave things here as-is for now.

Let me know if you run into any issues with the above mentioned pull request, if you happen to try it out.

@mihe mihe closed this as not planned Won't fix, can't repro, duplicate, stale Dec 31, 2024
@mihe mihe changed the title Performance problems involving max_bodies project settings Many static bodies cause severe slowdowns Dec 31, 2024
@mihe mihe added the wontfix This will not be worked on label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Something isn't as fast as it probably could be topic:runtime Concerning runtime behavior (or its source code) wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants