Implement as smarter `Buffer.write` to avoid a lot of overhead. Consider the following example: ```js poolOffset += poolBuffer.asciiWrite(`{"seq":`, poolOffset) poolOffset += poolBuffer.asciiWrite(seq, poolOffset) poolOffset += poolBuffer.asciiWrite(`,"id":"`, poolOffset) poolOffset += key.copy(poolBuffer, poolOffset) poolOffset += poolBuffer.asciiWrite(`","changes":[{"rev":"`, poolOffset) poolOffset += version.copy(poolBuffer, poolOffset) poolOffset += poolBuffer.asciiWrite(`"}]`, poolOffset) ``` Could be reduced to: ```js poolOffset += poolBuffer.write([ `{"seq":`, seq, `,"id":"`, key, `","changes":[{"rev":"`, version, `"}]` ], poolOffset, 'ascii') ``` and avoid a lot of js -> cpp calls
Activity
lemire commentedon May 20, 2024
It might be useful to elaborate. Why does this require new functionality in Buffer? Can't this be improved already?
(I am not being argumentative, this is a genuine question.)
ronag commentedon May 20, 2024
How would you improve it? I think part of the problem is the number of times a js/c++ boundary needs to be crossed.
ronag commentedon May 20, 2024
Maybe use fastcall for asciiWrite?