Different performance between reduce(map()) and mapreduce()

reduce has a specialization for vcat where it preallocates an output array first and then loops over to fill it. mapreduce isn’t so clever here.

See Optimized methods for `mapreduce(f, vcat, xs)` and `mapreduce(f, hcat, xs)` · Issue #31137 · JuliaLang/julia · GitHub

It is a bit unfortunate that specializations for vcat/hcat are not mentioned in the documentation AFAICT.

3 Likes