Comparing version 2.19.6 to 2.19.7
48
index.js
@@ -9,2 +9,3 @@ const codecs = require('codecs') | ||
const Xache = require('xache') | ||
const { all: unslabAll } = require('unslab') | ||
@@ -41,4 +42,4 @@ const RangeIterator = require('./iterators/range') | ||
class Cache { | ||
constructor () { | ||
this.keys = new Xache({ maxSize: 65536 }) | ||
constructor (maxSize) { | ||
this.keys = new Xache({ maxSize }) | ||
this.length = 0 | ||
@@ -390,5 +391,7 @@ } | ||
this._sessions = opts.sessions !== false | ||
this._keyCache = new Cache() | ||
this._nodeCache = new Cache() | ||
const maxCacheSize = opts.maxCacheSize || 65536 | ||
this._keyCache = new Cache(maxCacheSize) | ||
this._nodeCache = new Cache(maxCacheSize) | ||
this._batches = [] | ||
@@ -434,2 +437,7 @@ | ||
get maxCacheSize () { | ||
// Note: the key cache and the node cache have the same size | ||
return this._keyCache.keys.maxSize | ||
} | ||
replicate (isInitiator, opts) { | ||
@@ -741,8 +749,3 @@ return this.core.replicate(isInitiator, opts) | ||
if (entry === null) throw BLOCK_NOT_AVAILABLE() | ||
const wrap = { | ||
key: entry.key, | ||
value: entry.value, | ||
index: entry.index, | ||
inflated: null | ||
} | ||
const wrap = copyEntry(entry) | ||
if (this.core.fork === this.tree.core.fork) this.tree._nodeCache.set(seq, wrap) | ||
@@ -1561,2 +1564,27 @@ return wrap | ||
function copyEntry (entry) { | ||
let key = entry.key | ||
let value = entry.value | ||
let index = entry.index | ||
// key, value and index all refer to the same buffer (one hypercore block) | ||
// If together they are larger than half the buffer's byteLength, | ||
// this means that they got their own private slab (see Buffer.allocUnsafe docs) | ||
// so no need to unslab | ||
const size = key.byteLength + (value === null ? 0 : value.byteLength) + (index === null ? 0 : index.byteLength) | ||
if (2 * size < key.buffer.byteLength) { | ||
const [newKey, newValue, newIndex] = unslabAll([entry.key, entry.value, entry.index]) | ||
key = newKey | ||
value = newValue | ||
index = newIndex | ||
} | ||
return { | ||
key, | ||
value, | ||
index, | ||
inflated: null | ||
} | ||
} | ||
function defaultDiffer (currentSnap, previousSnap, opts) { | ||
@@ -1563,0 +1591,0 @@ return currentSnap.createDiffStream(previousSnap, opts) |
{ | ||
"name": "hyperbee", | ||
"version": "2.19.6", | ||
"version": "2.19.7", | ||
"description": "An append-only B-tree running on a Hypercore.", | ||
@@ -21,2 +21,3 @@ "main": "index.js", | ||
"streamx": "^2.12.4", | ||
"unslab": "^1.2.0", | ||
"xache": "^1.2.1" | ||
@@ -31,2 +32,3 @@ }, | ||
"sub-encoder": "^1.0.6", | ||
"test-tmp": "^1.2.1", | ||
"tree-to-string": "^1.1.1" | ||
@@ -33,0 +35,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97626
2696
11
8
+ Addedunslab@^1.2.0
+ Addedunslab@1.3.0(transitive)