vulkano-rs / vulkano

Safe and rich Rust wrapper around the Vulkan API
Apache License 2.0
4.48k stars 433 forks source link

Replace `host::PoolAllocator` with `slabbin::SlabAllocator` #2493

Closed marc0246 closed 6 months ago

marc0246 commented 6 months ago

This replaces the very questionable host::PoolAllocator with slabbin::SlabAllocator. The previous allocator was always just a stand-in for something more optimal anyway. The reason this is faster is because there isn't an additional computation when indexing, rather a raw pointer can be dereferenced directly.

I benchmarked allocating and deallocating 100,000 suballocations and this is the result:

test tests::before ... bench:   2,962,433 ns/iter (+/- 90,702)
test tests::after  ... bench:   2,307,794 ns/iter (+/- 84,225)

Which looks like a 23% performance increase.

Note that the new code is no more unsafe than the old one. The unsafe was just very badly indicated :sweat_smile: which I fixed now.

This dependency will come in handly to speed up all kinds of internal data structures: I plan to use it for BuddyAllocator next and for a future FlsfAllocator, as well as for our range map and a future image subresource range map.