Skip to content

Performance regression in pipe after v0.11.3 on OS X #3475

Closed
@mhart

Description

@mhart

(extracted from #3429 because that's specifically about the disparity between stdin and spawn)

This graph shows the performance of cat file | node readStdin.js on different node.js versions on OS X 10.11:

stdin

This was generated from 11 runs of the following program after cat/piping a 1GB file generated with head -c 1000000000 /dev/zero > file:

stdinPipe(function(err, time) {
  if (err) return console.error(err.stack || err)
  console.log([process.version, time].join(','))
})

function stdinPipe(cb) {
  var bytesRead = 0
  var time = process.hrtime()

  process.stdin.resume()
  process.stdin.on('data', function(data) {
    bytesRead += data.length
  })
  process.stdin.on('error', cb)
  process.stdin.on('end', function() {
    if (bytesRead != 1000000000) return cb(new Error('Incorrect bytes read: ' + bytesRead))
    var diff = process.hrtime(time)
    cb(null, 1000 / (diff[0] + diff[1] / 1e9))
  })
}

Now interestingly, as far as I can tell this seems to be a specifically pipe-related problem, because if the same program is run with node readStdin.js < file, no such difference exists:

stdinread

Metadata

Metadata

Assignees

Labels

benchmarkIssues and PRs related to the benchmark subsystem.macosIssues and PRs related to the macOS platform / OSX.streamIssues and PRs related to the stream subsystem.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions