samsa icon indicating copy to clipboard operation
samsa copied to clipboard

Stop using Node.js Buffer

Open Lorp opened this issue 2 years ago • 1 comments

Using Buffer in Node.js is inefficient compared with DataView and ArrayBuffer (which are available everywhere). Much better to subclass DataView and at the same time handle pointer increments within the class.

Lorp avatar May 22 '23 16:05 Lorp

Test on writing uint32 values into 100000000 bytes. Timings after warmup:

DataView: 35.777ms
DataView subclass: 39.698ms
Buffer: 182.879ms

So by moving to DataView subclass we sacrifice 10% speed, but gain significantly in code clarity and error avoidance.

Lorp avatar May 22 '23 17:05 Lorp