Slow Vectors?

Remi Forax forax at univ-mlv.fr
Thu Jun 3 16:33:33 UTC 2021


----- Mail original -----
> De: "Mark Hammons" <markehammons at gmail.com>
> À: "panama-dev at openjdk.java.net'" <panama-dev at openjdk.java.net>
> Envoyé: Jeudi 3 Juin 2021 17:51:29
> Objet: Slow Vectors?

> Hi all,
> 
> I tried testing the incubator vector api today with the following code in
> JMH
> 
> val panamaIntVecAdder = (a: Array[Int], b: Array[Int]) => {
>> var i = 0
>> val nArr = Array.ofDim[Int](a.size)
>> val species = IntVector.SPECIES_PREFERRED
>> while i < a.size do
>> val m = species.indexInRange(i, a.length)
>> val va = IntVector.fromArray(species, a, i, m)
>> val vb = IntVector.fromArray(species, b, i, m)
>>
>> va.add(vb).intoArray(nArr, i, m)
>> i += species.length
>> ArraySeq.unsafeWrapArray(nArr)
>> }
>>
> 
> It works, but it's very slow, averaging about  154.038 ns/op. The
> simplistic vector addition implementation I wrote beats it very easily,
> which I found very suprising. My current jdk is # VM version: JDK 16.0.1,
> OpenJDK 64-Bit Server VM, 16.0.1+9-24.
> 
> Any idea what I'm doing wrong here?

reading and writing from a non constant mask is slow with Java 16,
because it uses blend under the cover.

using JMH, you can use hsdis [1] + JMH perfasm profiler to get the generated assembly code

regards,
Rémi

[1] https://www.morling.dev/blog/building-hsdis-for-openjdk-15/


More information about the panama-dev mailing list