Hmm... ran into a strange issue. Maybe there's something really plain I'm not seeing here. Here are non-scalarized & scalarized versions of two expressions. For some reason, the second causes a test to be much slower and have lots of more vector
creations. I can't really see how more vectors could get created here, though... Can anyone see something I might be missing?
Code:
// xf2 is a Transform, vertices2 is an array of vectors
// non-scalarized
xf2 * vertices2(i1)
xf2 * vertices2(i2)
// scalarized
new Vector2(
xf2.pos.x + xf2.rot.a11 * vertices2(i1).x + xf2.rot.a12 * vertices2(i1).y,
xf2.pos.y + xf2.rot.a21 * vertices2(i1).x + xf2.rot.a22 * vertices2(i1).y
)
new Vector2(
xf2.pos.x + xf2.rot.a11 * vertices2(i2).x + xf2.rot.a12 * vertices2(i2).y,
xf2.pos.y + xf2.rot.a21 * vertices2(i2).x + xf2.rot.a22 * vertices2(i2).y
)
Note that I'm working on skipping scalarization for expressions like this: I think there is no improvement here, as they create a new vector in any case and normal inlining at compile time or by JIT should have the same result.
Oh, and these expressions in context:
Code:
// original (last statement of PolygonCollider.findIncidentEdge)
scala.List.apply[org.villane.box2d.collision.PolygonCollider.ClipVertex](new org.villane.box2d.collision.PolygonCollider.ClipVertex(xf2.*(vertices2.apply(i1)), new org.villane.box2d.collision.ContactID(edge1, i1, 0, false)), new org.villane.box2d.collision.PolygonCollider.ClipVertex(xf2.*(vertices2.apply(i2)), new org.villane.box2d.collision.ContactID(edge1, i2, 1, false)))
// scalarized
scala.List.apply[org.villane.box2d.collision.PolygonCollider.ClipVertex](new org.villane.box2d.collision.PolygonCollider.ClipVertex(new org.villane.vecmath.Vector2(xf2.pos.x.+(xf2.rot.a11.*(vertices2.apply(i1).x).+(xf2.rot.a12.*(vertices2.apply(i1).y))), xf2.pos.y.+(xf2.rot.a21.*(vertices2.apply(i1).x).+(xf2.rot.a22.*(vertices2.apply(i1).y)))), new org.villane.box2d.collision.ContactID(edge1, i1, 0, false)), new org.villane.box2d.collision.PolygonCollider.ClipVertex(new org.villane.vecmath.Vector2(xf2.pos.x.+(xf2.rot.a11.*(vertices2.apply(i2).x).+(xf2.rot.a12.*(vertices2.apply(i2).y))), xf2.pos.y.+(xf2.rot.a21.*(vertices2.apply(i2).x).+(xf2.rot.a22.*(vertices2.apply(i2).y)))), new org.villane.box2d.collision.ContactID(edge1, i2, 1, false)))
[edit] This also happens if I'll do this replacement manually and don't compile with the optimizer.