Bytecoder icon indicating copy to clipboard operation
Bytecoder copied to clipboard

Populating typed arrays faster

Open neuronsupport opened this issue 5 years ago • 4 comments

Support for set(array) methods for IntArray and FloatArray is needed for performance. It is also possible to create typed arrays using additional OpaqueArray create methods which would accept an existing array. Moreover, a reference by conversion from Java primitive arrays to typed arrays (and vice versa) would be provided for higher performance.

How is passing an Int32Array from Javascript to Java or and int[] array from Java to Javascript handled by bytecoder?

neuronsupport avatar Feb 02 '19 12:02 neuronsupport

The JS backend translates TypedArray invocation directly to calls of the JS reference. There is no performance penalty here.

WASM backend is a different beast. As WASM backend currently does not provide the Reference Types Proposal, JS references are indirectly stored in a mapping table on JS side. Calls to TypedArray instances are first processed by resolving the instance from the mapping table and then the actual invocation is performed. To there is a performance penalty by crossing the WASM to JS border and then by the table lookup.

mirkosertic avatar Feb 04 '19 16:02 mirkosertic

toArray and fromArray methods to TypedArrays would help a lot performance wise. Such as

byte[] toArray()
void fromArray(byte[] array) 

for Int8Array class

int[] toArray()
void fromArray(int[] array) 

for IntArray class

float[] toArray()
void fromArray(float[] array) 

for FloatArray class

neuronsupport avatar Sep 05 '19 13:09 neuronsupport

I think this can be implemented by a bulk-copy from and to the Wasm memory with some utility functions on JS side. Do you have an example for the current implementation and the performance impact? We need a baseline to measure possible improvements.

mirkosertic avatar Mar 03 '20 17:03 mirkosertic

I really havent used these. I was just suggesting that it would be good have these methods for performance. Sorry I have no example code for this one.

neuronsupport avatar Mar 08 '20 18:03 neuronsupport

Closed due to no further feedback.

mirkosertic avatar Mar 29 '23 16:03 mirkosertic