github.com/jussi-kalliokoski/quickfilter (go): Package quickfilter provides a QuickFilter module for performing filtering of slices with minimal allocations. It works by allocating a bit array that stores the indices of the elements to be added to the resulting slice. This means that the total number of allocations for the filtering operation will be a static two (2), `len(sourceSlice)/8` bytes for the bit array and `len(resultSlice)*size_of_element` for the results array. This helps with providing predictable performance for your filter operations.  QuickFilter should not be used blindly due to the readability overhead, and it may not even be the fastest option available. Usually it's more efficient to do the operation in-place if you can mutate the original slice. You can see an example of this in the benchmarks. You might also consider using resource pooling instead. As always, optimize when needed and benchmark to find the best solution.  For reference, here are the benchmark results on a MacBook Pro (early 2015, 3.1GHz i7, 16GB memory) of filtering a large arbitrary payload:  As we can see, QuickFilter is more than twice as fast as using dynamic allocations, allocates almost a third of the memory, and is almost as fast as doing the operation in-place.
Keywords: filtering|go|golang|performance