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

Ability to re-use BVH allocations? #75

Open
heyx3 opened this issue Mar 20, 2024 · 1 comment
Open

Ability to re-use BVH allocations? #75

heyx3 opened this issue Mar 20, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@heyx3
Copy link

heyx3 commented Mar 20, 2024

Currently, if I'm reading the builders correctly, they always allocate a new bvh instance when building. It would be nice to have the option of re-using allocations.

@madmann91
Copy link
Owner

It's unclear how to pass existing allocations/BVHs/buffers to the BVH builders. For instance, the mini tree builder needs to create mini-trees that require their own allocations of impredictable size, and other builders over-allocate in order to avoid allocating often when building the tree (they over-allocate, then shrink the resulting buffers). This design is very efficient and simple and I would like to keep it as it is.

While it is theoretically possible to pass an additional buffer for builders other than the mini-tree one, there's a good chance that it won't be large enough anyway (due to the over-allocation+shrinking design). That said, if your only concern is performance, you can just drop your old BVH right before building a new one with the same size, and the OS will likely re-use the blocks that were just freed.

If your concern is running this code in an embedded scenario, or some other application where allocations should be tightly controlled, the real solution here would be to use custom STL allocators (that would allow the builders to use a pool-based allocator, for instance). I am open to a PR tackling that problem, if you have the time.

@madmann91 madmann91 added enhancement New feature or request help wanted Extra attention is needed labels Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants