-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
50% performance increase in ReadStream by removing one bind.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,15 +117,18 @@ ReadStream.prototype.pipe = function (dest) { | |
} | ||
|
||
ReadStream.prototype._read = function () { | ||
var that = this | ||
if (this._state.canRead()) { | ||
this._state.read() | ||
this._iterator.next(this._onData.bind(this)) | ||
this._iterator.next(function(err, key, value) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jdalton
|
||
that._onData(err, key, value) | ||
}) | ||
} | ||
} | ||
|
||
ReadStream.prototype._onData = function (err, key, value) { | ||
this._state.endRead() | ||
if (err || !arguments.length /* end */ || !this._state.canEmitData()) | ||
if (err || (key === undefined && value === undefined) || !this._state.canEmitData()) | ||
return this._cleanup(err) | ||
this._read() // queue another read even tho we may not need it | ||
try { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
var setupFn = function (count, db, cb) { | ||
var doWrites = function() { | ||
if(--count === 0) return cb() | ||
db.put("aa" + count, "bb" + count, doWrites) | ||
} | ||
doWrites() | ||
} | ||
|
||
, fn = function (db, cb) { | ||
db.createReadStream().on("end", cb) | ||
} | ||
|
||
module.exports = fn | ||
module.exports.fn = fn | ||
module.exports.setup = setupFn.bind(null, 100000) | ||
module.exports.setupFn = setupFn |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
module.exports = require("./readStream_x100000_levelup").fn.bind(null) | ||
module.exports.setup = require("./readStream_x100000_levelup").setupFn.bind(null, 10000) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
module.exports = require("./readStream_x100000_levelup").fn.bind(null) | ||
module.exports.setup = require("./readStream_x100000_levelup").setupFn.bind(null, 1000) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
module.exports = require("./readStream_x100000_levelup").fn.bind(null) | ||
module.exports.setup = require("./readStream_x100000_levelup").setupFn.bind(null, 100) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
module.exports = require("./readStream_x100000_levelup").fn.bind(null) | ||
module.exports.setup = require("./readStream_x100000_levelup").setupFn.bind(null, 10) |
You can optimize this further!
The gist is if the
onData
callback doesn't referencethis
then it doesn't get wrapped.