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

Parallel BVH creation using rayon #2

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Elabajaba
Copy link

This is essentially just a port of the parallel bvh creation from svenstaro#80
Most of the added code outside the build functions was added for testing, with the main changes being the build functions being rewritten to work on mutable slices of indices instead of recursively passing back an index.

Based on the polyanya baking bench, this is about 10% faster singlethreaded (with the rayon feature disabled, ~9.4ms main -> 8.4ms pr), or about 60% faster when multithreaded (~9.4ms main -> ~3.5ms pr). Even with a single thread rayon taskpool it's still faster than main (~8.9ms), and gets faster up until 4-5 threads on my machine, at which point gains become tiny, then non existent (2Threads: ~5.5ms, 4T: ~3.8ms, 6T: ~3.4ms, 8T: ~3.4ms)

I had a bevy tasks implementation as well, but it was quite a bit slower than the single threaded version so I didn't bother with it.

@Elabajaba Elabajaba marked this pull request as draft January 1, 2023 22:27
@Elabajaba
Copy link
Author

Turns out this can be almost as performant with bevy tasks as it is with rayon so long as the number of tasks (parallel recurse iterations) is heavily limited.

Rayon seems to perform better with more tasks than bevy tasks.

Not sure if it should be user configurable, or automatic based on the detected number of cpus, or if it should just have a static max total number of tasks.

Also this leads to conflicting features. I'm currently just panicking at runtime if it detects both the bevy and rayon features enabled at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant