Closed jhugman closed 1 month ago
Using typed arrays had a number of disadvantages, most notably:
This resulted in lots of copying. For example, when writing a BigInt to the byte offset 11 a destination ArrayBuffer:
BigInt
ArrayBuffer
Uint64Array
Uint8Array
This was a lot of work for a single write: steps 1, 3, 4 and 6 involve O(n) work.
O(n)
This PR replaces the typed arrays with a DataView which is a lot simpler:
DataView
Only step 2 involves O(n) work.
The work allowed us to simplify the RustBuffer: the read and write method are both replaced by two simpler methods:
RustBuffer
read
write
readWithView
readBytes
writeWithView
writeBytes
Using typed arrays had a number of disadvantages, most notably:
This resulted in lots of copying. For example, when writing a
BigInt
to the byte offset 11 a destinationArrayBuffer
:ArrayBuffer
of 8 bytes was createdUint64Array
typed array was created to view that transitional ArrayBuffer.BigInt
was written into theUint64Array
, i.e. the transitional array.Uint8Array
view was created for each of the transitional array and the destination array.This was a lot of work for a single write: steps 1, 3, 4 and 6 involve
O(n)
work.This PR replaces the typed arrays with a
DataView
which is a lot simpler:DataView
of the destination array is createdBigInt
is written into theDataView
, of the correct endianness.Only step 2 involves
O(n)
work.The work allowed us to simplify the
RustBuffer
: theread
andwrite
method are both replaced by two simpler methods:readWithView
andreadBytes
.writeWithView
andwriteBytes
.