optimize blockdb more.

This commit is contained in:
Christopher Jeffrey 2016-02-15 10:54:04 -08:00
parent 124e79907b
commit 91897540d6
2 changed files with 35 additions and 1 deletions

View File

@ -60,9 +60,14 @@ BlockDB.prototype.createOffset = function createOffset(size, offset, height) {
};
BlockDB.prototype.parseOffset = function parseOffset(data) {
// Avoid using bignumbers here to increase performance.
// This is safe because this number will never exceed
// 53 bits (up to 8.3 petabytes).
var hi = utils.readU32(data, 8);
var lo = utils.readU32(data, 4);
return {
size: utils.readU32(data, 0),
offset: utils.readU64(data, 4).toNumber(),
offset: (hi * 0x100000000) + lo,
height: utils.readU32(data, 12)
};
};
@ -367,6 +372,31 @@ BlockDB.prototype._getCoinsByAddress = function _getCoinsByAddress(address, call
callback = utils.asyncify(callback);
/*
stream = this.index.createKeyStream({
start: 'u/a/' + address,
end: 'u/a/' + address + '~'
});
stream.on('data', function(key) {
var parts = key.split('/').slice(3);
var hash = parts[0];
var index = +parts[1];
pending++;
self.index.get('u/t/' + hash + '/' + index, function(err, data) {
if (err && err.type !== 'NotFoundError')
return callback(err);
if (data)
coins.push(data);
pending--;
if (done) {
if (!pending)
return callback(null, coins);
}
});
});
*/
stream = this.index.createReadStream({
start: 'u/a/' + address,
end: 'u/a/' + address + '~'
@ -677,6 +707,7 @@ BlockData.prototype._init = function _init() {
};
BlockData.prototype._malloc = function(size) {
return new Buffer(size);
if (!this._bufferPool[size])
this._bufferPool[size] = new Buffer(size);
@ -689,6 +720,7 @@ BlockData.prototype._malloc = function(size) {
};
BlockData.prototype._free = function(buf) {
return;
if (this._bufferPool.used[buf.length] === buf) {
assert(this._bufferPool[buf.length] === buf);
delete this._bufferPool.used[buf.length];

View File

@ -66,12 +66,14 @@ Node.prototype._init = function _init() {
throw err;
self.mempool.addBlock(block);
if (0)
var hash = block.txs[0].hash('hex');
if (0)
self.storage.getTX(hash, function(err, tx) {
if (err) throw err;
utils.print(tx);
});
if (0)
self.storage.getCoin(hash, 0, function(err, tx) {
if (err) throw err;
utils.print(tx);