Blind optimizations; Making Bloom Filter faster
In optimizing the code from Maybe.NET I’m not actually making any structural changes, I’m merely going over the code and fixing idiomatic C# code that has unacceptable performance behavior from my point of view.
For example, let’s take this code, the code of the Bloom Filter algorithm:
This will allocate a state object for the closure, and we’ll have a delegate invocation cost to pay. We also saw the other costs that are paid here in the previous post (since this call the to the MurmurHash3 implementation), so I’ll ignore it.
I’m going to use Memory<byte> as the underlying data structure, because that gives me nice abstraction over the memory. I’m using Memory<byte> instead of Span<byte> because I’m going to have the Bloom Filter on the heap, not just on the stack, so we can’t use Span. Here is the full code:
Note that there are no allocations at all during the critical operations.