Comparing version 2.2.1 to 2.2.2
export let Env, Compression, Cursor, getAddress, clearKeptObjects, setGlobalBuffer, | ||
require, arch, fs, os, onExit, tmpdir, lmdbError, path, EventEmitter, orderedBinary, MsgpackrEncoder, WeakLRUCache; | ||
require, arch, fs, os, onExit, tmpdir, lmdbError, path, EventEmitter, orderedBinary, MsgpackrEncoder, WeakLRUCache, isWorkerThread; | ||
export function setNativeFunctions(externals) { | ||
@@ -26,2 +26,3 @@ Env = externals.Env; | ||
onExit = externals.onExit; | ||
isWorkerThread = externals.isWorkerThread; | ||
} |
@@ -58,3 +58,3 @@ import { fileURLToPath } from './deps.ts'; | ||
setGlobalBuffer: { parameters: ['pointer', 'usize'], result: 'void'}, | ||
setCompressionBuffer: { parameters: ['f64', 'pointer', 'usize', 'u32'], result: 'void'}, | ||
setCompressionBuffer: { parameters: ['f64', 'pointer', 'u32', 'pointer', 'u32'], result: 'void'}, | ||
newCompression: { parameters: ['pointer', 'usize', 'u32'], result: 'u64'}, | ||
@@ -201,4 +201,4 @@ prefetch: { parameters: ['f64', 'f64'], nonblocking: true, result: 'i32'}, | ||
} | ||
setBuffer(bytes: Uint8Array, dictLength: number) { | ||
setCompressionBuffer(this.address, bytes, bytes.length, dictLength); | ||
setBuffer(target: Uint8Array, targetLength: number, dictionary: Uint8Array, dictLength: number) { | ||
setCompressionBuffer(this.address, target, targetLength, dictionary, dictLength); | ||
} | ||
@@ -205,0 +205,0 @@ } |
@@ -12,2 +12,3 @@ import { createRequire } from 'module'; | ||
import * as orderedBinary from 'ordered-binary'; | ||
import { isMainThread } from 'worker_threads'; | ||
orderedBinary.enableNullTermination(); | ||
@@ -24,3 +25,4 @@ | ||
process.on('exit', callback); | ||
} | ||
}, | ||
isWorkerThread: !isMainThread, | ||
}); | ||
@@ -27,0 +29,0 @@ export { toBufferKey as keyValueToBuffer, compareKeys, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary'; |
@@ -1,2 +0,2 @@ | ||
import { Compression, getAddress, require, arch, fs, path as pathModule, lmdbError, EventEmitter, MsgpackrEncoder, Env, tmpdir, os } from './external.js'; | ||
import { Compression, getAddress, require, arch, fs, path as pathModule, lmdbError, EventEmitter, MsgpackrEncoder, Env, tmpdir, os, isWorkerThread } from './external.js'; | ||
import { CachingStore, setGetLastVersion } from './caching.js'; | ||
@@ -10,2 +10,3 @@ import { addReadMethods, makeReusableBuffer } from './read.js'; | ||
// this is hard coded as an upper limit because it is important assumption of the fixed buffers in writing instructions | ||
@@ -53,3 +54,3 @@ // this corresponds to the max key size for 8KB pages, which is currently the default | ||
pageSize: 4096, | ||
overlappingSync: (options && (options.noSync || options.readOnly)) ? false : os != 'win32', | ||
overlappingSync: (options && (options.noSync || options.readOnly)) ? false : (os != 'win32' && !isWorkerThread), | ||
// default map size limit of 4 exabytes when using remapChunks, since it is not preallocated and we can | ||
@@ -56,0 +57,0 @@ // make it super huge. |
{ | ||
"name": "lmdb", | ||
"author": "Kris Zyp", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Simple, efficient, scalable, high-performance LMDB interface", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
49
read.js
@@ -6,4 +6,6 @@ import { RangeIterable } from './util/RangeIterable.js'; | ||
const Uint8ArraySlice = Uint8Array.prototype.slice; | ||
const Uint8A = typeof Buffer != 'undefined' ? Buffer.allocUnsafeSlow : Uint8Array | ||
let getValueBytes = makeReusableBuffer(0); | ||
const START_ADDRESS_POSITION = 4064; | ||
const NEW_BUFFER_THRESHOLD = 0x10000; | ||
@@ -34,3 +36,5 @@ export function addReadMethods(LMDBStore, { | ||
if (error.message.startsWith('MDB_BAD_VALSIZE') && this.writeKey(id, keyBytes, 0) == 0) | ||
error = new Error('Zero length key is not allowed in LMDB') | ||
error = new Error(id === undefined ? | ||
'A key is required for get, but is undefined' : | ||
'Zero length key is not allowed in LMDB') | ||
throw error | ||
@@ -44,6 +48,6 @@ } | ||
return; | ||
/*if (returnNullWhenBig && this.lastSize >= 0x10000) | ||
if (returnNullWhenBig && this.lastSize > NEW_BUFFER_THRESHOLD) | ||
// used by getBinary to indicate it should create a dedicated buffer to receive this | ||
return null;*/ | ||
if (this.lastSize >= 0x10000 && !compression && this.db.getSharedByBinary) { | ||
return null; | ||
if (this.lastSize > NEW_BUFFER_THRESHOLD && !compression && this.db.getSharedByBinary) { | ||
// for large binary objects, cheaper to make a buffer that directly points at the shared LMDB memory to avoid copying a large amount of memory, but only for large data since there is significant overhead to instantiating the buffer | ||
@@ -62,14 +66,13 @@ if (this.lastShared) // we have to detach the last one, or else could crash due to two buffers pointing at same location | ||
}, | ||
_allocateGetBuffer(lastSize, exactSize) { | ||
let newLength = exactSize ? lastSize : Math.min(Math.max(lastSize * 2, 0x1000), 0xfffffff8); | ||
_allocateGetBuffer(lastSize) { | ||
let newLength = Math.min(Math.max(lastSize * 2, 0x1000), 0xfffffff8); | ||
let bytes; | ||
if (this.compression) { | ||
let dictionary = this.compression.dictionary || []; | ||
let dictionary = this.compression.dictionary || new Uint8A(0); | ||
let dictLength = (dictionary.length >> 3) << 3;// make sure it is word-aligned | ||
bytes = makeReusableBuffer(newLength + dictLength); | ||
bytes = new Uint8A(newLength + dictLength); | ||
bytes.set(dictionary) // copy dictionary into start | ||
this.compression.setBuffer(bytes, dictLength); | ||
this.compression.fullBytes = bytes; | ||
// the section after the dictionary is the target area for get values | ||
bytes = bytes.subarray(dictLength); | ||
this.compression.setBuffer(bytes, newLength, dictionary, dictLength); | ||
bytes.maxLength = newLength; | ||
@@ -80,4 +83,3 @@ Object.defineProperty(bytes, 'length', { value: newLength, writable: true, configurable: true }); | ||
bytes = makeReusableBuffer(newLength); | ||
setGlobalBuffer(bytes); | ||
getValueBytes = bytes; | ||
setGlobalBuffer(getValueBytes = bytes); | ||
} | ||
@@ -87,5 +89,3 @@ return bytes; | ||
getBinary(id) { | ||
let fastBuffer = this.getBinaryFast(id); | ||
return fastBuffer && Uint8ArraySlice.call(fastBuffer, 0, this.lastSize);/* | ||
let bytesToRestore, compressionBytesToRestore; | ||
let bytesToRestore; | ||
try { | ||
@@ -97,7 +97,11 @@ returnNullWhenBig = true; | ||
bytesToRestore = this.compression.getValueBytes; | ||
compressionBytesToRestore = this.compression.fullBytes; | ||
} else | ||
let dictionary = this.compression.dictionary || []; | ||
let dictLength = (dictionary.length >> 3) << 3;// make sure it is word-aligned | ||
let bytes = makeReusableBuffer(this.lastSize); | ||
this.compression.setBuffer(bytes, this.lastSize, dictionary, dictLength); | ||
this.compression.getValueBytes = bytes; | ||
} else { | ||
bytesToRestore = getValueBytes; | ||
// allocate buffer specifically for this get | ||
this._allocateGetBuffer(this.lastSize, true); | ||
setGlobalBuffer(getValueBytes = makeReusableBuffer(this.lastSize)); | ||
} | ||
return this.getBinaryFast(id); | ||
@@ -109,7 +113,6 @@ } | ||
if (bytesToRestore) { | ||
if (compressionBytesToRestore) { | ||
if (this.compression) { | ||
let compression = this.compression; | ||
let dictLength = (compression.dictionary.length >> 3) << 3; | ||
compression.setBuffer(compressionBytesToRestore, dictLength); | ||
compression.fullBytes = compressionBytesToRestore; | ||
compression.setBuffer(bytesToRestore, bytesToRestore.maxLength, compression.dictionary, dictLength); | ||
compression.getValueBytes = bytesToRestore; | ||
@@ -121,3 +124,3 @@ } else { | ||
} | ||
}*/ | ||
} | ||
}, | ||
@@ -124,0 +127,0 @@ get(id) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
20408118
5130