The javascript code does not seem optimal.
Avoid using ‘data.buffer.slice()’ as it allocates memory and creates a copy.
Have you tried using ‘new DataView(data.buffer, byteOffset, byteLength)’ to reference the same buffer?
If you need more performance, you may also use ‘new Uint8Array(data.buffer, byteOffset, length)’ which is common practice.