HarlanH/julia — comment on commit 5976095f49f85a133803475757b92f8c5e55b036
File:  line 0
By StefanKarpinski:

This feels a bit inefficient, but I'm not sure that anything else would actually be better. Incrementally growing the output is almost always the slowest way to go, so that's not going to be better. That means that you have to know how many result cells to allocate first, implying that you need to evaluate the filter condition on each input value before ever allocating or storing the output. If you want to evaluate each function only once (which we do because each evaluation could be expensive and/or have side-effects), then you need to store the results somewhere, which is precisely what you do with the boolean vector. The implementation of boolean indexing counts the true values and allocates the result accordingly, so that's efficient. So yeah, I actually think this is as good as one can do. We've talked about using packed bit arrays for vectors of booleans, but we haven't done that yet. That would be an 8x reduction in temporary memory overhead.