nodejs / nodejs/performance

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

Open
#168 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
399
Forks
11
Avg merge
29m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing Buffer.write entry point and the mixed string, Array, and Buffer signature described in the issue. Done means the shown call works with the offset and encoding while avoiding the repeated JavaScript-to-C++ calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.