dop251 / goja

ECMAScript/JavaScript engine in pure Go
MIT License
5.63k stars 378 forks source link

Convert []uint8 to Uint8Array #574

Closed devsnek closed 4 months ago

devsnek commented 6 months ago

Turns []uint8 into Uint8Array instead of a go array proxy.

dop251 commented 5 months ago

I can see two issues:

  1. Compatibility. This change would break existing code.
  2. Performance. Due to the way typed arrays are implemented, you have to create an ArrayBuffer as well which roughly doubles the number of allocs. I was thinking about making ArrayBuffer allocations lazy, but it's proved to be too hard with the current code structure.
devsnek commented 5 months ago

regarding compatibility maybe there could be an option you can set on the runtime for it? i feel like at a high level it makes sense for []T to turn into the relevant TypedArray type.