fixedbitset icon indicating copy to clipboard operation
fixedbitset copied to clipboard

Possible performance optimizations

Open alice-i-cecile opened this issue 4 years ago • 8 comments

  1. fixedbitset could be allocation free for small block counts (store blocks in a SmallVec)
  2. fixedbitset could have a const constructor

From Bevy's ECS rework notes. Figured I'd pass the thoughts on here in case there's appetite to improve this.

alice-i-cecile avatar Mar 05 '21 01:03 alice-i-cecile

@alice-i-cecile could you elaborate on your first point. Fair warning I am still fairly new to rust so this might be a noob question. Are you suggesting that the struct FixedBitSet take a SmallVec of Blocks rather than a Vec?

AlvinKuruvilla avatar Aug 16 '21 19:08 AlvinKuruvilla

That's correct :) It looks like swapping to a SmallVec https://github.com/petgraph/fixedbitset/blob/5ae6d8c6175acea4ee1f8c704bc9de0122b72d0a/src/lib.rs#L61 should be a seamless replacement.

I would probably gate this behind a feature flag to allow users who don't want the extra dependency to opt out.

alice-i-cecile avatar Aug 16 '21 21:08 alice-i-cecile

Awesome I will get do my best to work on it

AlvinKuruvilla avatar Aug 16 '21 22:08 AlvinKuruvilla

@james7132 was the SmallVec in #74 problematic somehow? I'm interested in removing the Vec for small block counts and wondering if there's any particular direction we should explore next

grovesNL avatar Feb 12 '23 04:02 grovesNL

@james7132 was the SmallVec in #74 problematic somehow? I'm interested in removing the Vec for small block counts and wondering if there's any particular direction we should explore next

It had a strong regression for contains as it always needed to do the heap check every time. Definitely not ideal for use cases that heavily relied on contains checks.

james7132 avatar Feb 12 '23 04:02 james7132

FixedBitset::new is now const so one of the two parts of this issue have been resolved.

james7132 avatar Mar 16 '24 08:03 james7132

Maybe we can have a purely on stack version of fixedbitset with const generics?

Dan-wanna-M avatar May 28 '24 03:05 Dan-wanna-M

Maybe we can have a purely on stack version of fixedbitset with const generics?

I created a proof-of-concept crate for my own usage fixedbitset-stack . This is essentially a massive copy-paste of generics. I think the main design choice to make is whether to support operations between two sets on stack with different capacity though. I am not even sure that all operations can be supported given the limited capacity of Rust const generics.

Dan-wanna-M avatar Jun 18 '24 23:06 Dan-wanna-M