buffer: optimize Buffer#toString()
authorBen Noordhuis <info@bnoordhuis.nl>
Sun, 21 Jun 2015 20:32:22 +0000 (22:32 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Thu, 25 Jun 2015 16:32:15 +0000 (18:32 +0200)
commit8350f3a3a291fcd19df3261c3db3fe07c7590bb7
treed2b973b848d9444daf2be3bd98fdff822efe3aed
parent06721fe00589d9ad61fe8defcd31c5f40df72c9b
buffer: optimize Buffer#toString()

Break up Buffer#toString() into a fast and slow path.  The fast path
optimizes for zero-length buffers and no-arg method invocation.

The speedup for zero-length buffers is a satisfying 700%.  The no-arg
toString() operation gets faster by about 13% for a one-byte buffer.

This change exploits the fact that most Buffer#toString() calls are
plain no-arg method calls.  Rewriting the method to take no arguments
means a call doesn't go through an ArgumentsAdaptorTrampoline stack
frame in the common case.

PR-URL: https://github.com/nodejs/io.js/pull/2027
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Christian Tellnes <christian@tellnes.no>
Reviewed-By: Daniel Cousens <email@dcousens.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
benchmark/buffers/buffer-tostring.js [new file with mode: 0644]
lib/buffer.js