Replies: 5 comments 5 replies
-
I wonder if this could be due to bounds-check removal on arrays in general. Could you set up a benchmark that accesses elements at a number of random indices, instead of a linear walk? |
Beta Was this translation helpful? Give feedback.
-
@Joe4evr Interesting suggestion, I guess replacing:
with
should prevent this optimization? |
Beta Was this translation helpful? Give feedback.
-
Why not just one of the other constructors, and not allocate the boolean array at all? Eg, there's the |
Beta Was this translation helpful? Give feedback.
-
Since the We could potentially have some Conceptually some specialized |
Beta Was this translation helpful? Give feedback.
-
you could copy the code from https://source.dot.net/#System.Collections/System/Collections/BitArray.cs,19ad3f494f0dc7f6 and mutate it to you needs. |
Beta Was this translation helpful? Give feedback.
-
I'm currently working on a case where I have to find the best collection to hold a collection of bits indexed by an integer. This collection will be used frequently and contain 100 to 10K bits most of the time. Read/write access should be as fast as possible.
I've run the benchmark below which creates different bit collections and counts the number of bits which value is true. My conclusions are:
bool[]
is more than twice faster than usingBitArray
BitArray
allocates ~8 times less thanbool[]
as expectedBitArray
Gen0 GC is ~8 times less thanbool[]
as expectedBitArray
performance improvements detailed in Performance Improvements in .NET 5 only apply when the samebool[]
is used to create aBitArray
which has little value in my case since bits are always different (my understanding is that this is only helpful in a singletonBitArray
scenario?)My question is, considering this benchmark, is higher pressure on GC with better performance a better option or is it going to introduce GC performance issues down the line?
Side question: is there a reason why
BitArray
does not implementIEnumerable<bool>
?Beta Was this translation helpful? Give feedback.
All reactions