fosskers/scala-benchmarks

Avoid use of `Array.ofDim` in benchmarks

mpilquist opened this issue · 4 comments

Array.ofDim[A](size) takes a ClassTag[A], which involves a synchronization barrier when materializing. Unless specifically benchmarking ofDim, it would be better to use new Array[A](size) instead.

Thanks, I'll correct this.

Wait, is there ever a point to using ofDim, then?

I think the only use case for ofDim is when you are writing something that's polymorphic in element type. BTW, I've seen the synchronization barrier of materializing a ClassTag[Byte] in support of Array.ofDim[Byte] as a hotspot in very high traffic network applications.

in very high traffic network applications.

You're the networking guy, so I believe you.

Cool, then I can fix the benchmarks and make note of the difference between ofDim and direct construction. I feel like those points need to be collated into some sort of appendix, too, so that people can know exactly what to avoid at a glance.