Memory Segment efficient array handling
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Apr 1 11:25:13 UTC 2021
On 01/04/2021 05:58, Ty Young wrote:
> The amount of arguments that you have to pass to use that static
> method and its complexity is kind of egregious as-is the amount of
> overloads for everything in MemoryAccess.
Not too different from:
https://download.java.net/java/early_access/jdk16/docs/api/java.base/java/nio/ByteBuffer.html#put(byte%5B%5D)
(except that segment is passed as an extra parameter, since this is a
static method - in fact I think that is the _only_ extra argument
compared to the BB bulk put).
I think you keep going back to "memory segment should know its layout" -
this is a siren song - it seems to work well in few simple cases, but it
fails to scale to most complex use cases (e.g. you can only deal with
segment whose element type is fixed).
The idea that segment is just flat data, and layout is an orthogonal
overlay over that data - and that you can view the _same_ segment with
multiple lenses is a powerful one - all the composition in the library
is derived from that idea - and the very fact that _new_ methods such as
the ones we are talking about here can be added _outside_ the API, with
very very good performance result, is yet another sign that we have the
right set of primitives (for instance, such bulk routines could not have
been added, efficiently, by users for the BB API). While, for this round
of functions, we might decide to add them to MemoryAccess, I think over
time this will become a game of diminishing returns, where users might
need more obscure routines. So, the fact that some of these routines can
be added, w/o loss of efficiency, _outside_ the API, is a big win.
Maurizio
More information about the panama-dev
mailing list