Early draft proposal for Value Arrays

Frank van Heeswijk fvheeswijk at outlook.com
Wed Jul 16 10:18:01 UTC 2014

I have thought of a feature that would be very useful in practice and might actually be in the scope of the Valhalla project.
The outlined description below is a very early draft about Value Arrays and I am looking for opinions.

Let us start with a practical example, an high performance class that works with matrices stored as doubles.
As example we can take the 4 by 4 variant, which is used a lot in graphics, in Java 8 there are two issues:
1) Mathematical operations are cumbersome; if you create a new copy on every operation, then a lot of objects will be created and it will lead to garbage collection.
   The only alternative would be updating the object as you go (without creating a new instance), but it is tricky to work with such a class.
2) You want to ideally store the objects in an float[] m or in a float[][] m for easy access, but this also costs another object per instance.

I think that the first issue is fixed with the upcoming addition of Value Types.
However the second issue is not so easily fixed, therefore I would like to introduce the idea of Value Arrays:

    private final double[][] m;

The idea is that all array elements will be stored directly on the heap(?) and that no array object will be created at all.

I am also wondering to what extent this is possible, if at all:
1) Value Array with constant size, known at compile time.
2) Value Array with an unknown size, dynamically known at runtime.

So the expected behaviour would be that:

    private final double[][] m = new double[4][4];

would simply be equal to how matrices (4x4) are defined nowadays in practice:

    private final double m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44;

I think that the maintainability and readability of the code will be greatly improved with this feature and that the Valhalla project is the correct project to consider this feature.

More information about the valhalla-dev mailing list