Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer.write(Array<string|Buffer>, offset: number, encoding: string) #168

Open
ronag opened this issue May 20, 2024 · 3 comments
Open

Buffer.write(Array<string|Buffer>, offset: number, encoding: string) #168

ronag opened this issue May 20, 2024 · 3 comments

Comments

@ronag
Copy link
Member

ronag commented May 20, 2024

Implement as smarter Buffer.write to avoid a lot of overhead. Consider the following example:

      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:

poolOffset += poolBuffer.write([
  `{"seq":`,
  seq,
  `,"id":"`,
  key,
  `","changes":[{"rev":"`,
  version,
   `"}]`
], poolOffset, 'ascii')

and avoid a lot of js -> cpp calls

@lemire
Copy link
Member

lemire commented 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
Copy link
Member Author

ronag commented 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
Copy link
Member Author

ronag commented May 20, 2024

Maybe use fastcall for asciiWrite?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants