In C, it is a common practice to preallocate a buffer and reuse it to reduce the frequency of heap allocations. The Julia one is supposed to do this. Note that
b is declared outside all loops. If
resize!(b, 0) doesn’t shrink the capacity of
b, GC should be triggered rarely.
I have also tried to use Channel following this blog post. On a small output is it several times slower than my current implementation – Channel is a bad substitution of generator.
Anyway, sending me a faster PR is the best way to prove your point. Let numbers speak.