emoji-picker-element
Advanced tools
Comparing version 1.3.2 to 1.3.3
@@ -0,1 +1,10 @@ | ||
## [1.3.3](https://github.com/nolanlawson/emoji-picker-element/compare/v1.3.2...v1.3.3) (2020-12-25) | ||
### Performance Improvements | ||
* use batch cursor for full DB scan ([#94](https://github.com/nolanlawson/emoji-picker-element/issues/94)) ([e5b1750](https://github.com/nolanlawson/emoji-picker-element/commit/e5b17505722ea0800431b5b9b53d7d59d03142ab)) | ||
## [1.3.2](https://github.com/nolanlawson/emoji-picker-element/compare/v1.3.1...v1.3.2) (2020-12-24) | ||
@@ -2,0 +11,0 @@ |
@@ -319,15 +319,36 @@ function assertNonEmptyString (str) { | ||
async function doFullDatabaseScanForSingleResult (db, predicate) { | ||
// TODO: we could do batching here using getAll(). Not sure if it's worth the extra code though. | ||
// This batching algorithm is just a perf improvement over a basic | ||
// cursor. The BATCH_SIZE is an estimate of what would give the best | ||
// perf for doing a full DB scan (worst case). | ||
// | ||
// Mini-benchmark for determining the best batch size: | ||
// | ||
// PERF=1 yarn build:rollup && yarn test:adhoc | ||
// | ||
// (async () => { | ||
// performance.mark('start') | ||
// await $('emoji-picker').database.getEmojiByShortcode('doesnotexist') | ||
// performance.measure('total', 'start') | ||
// console.log(performance.getEntriesByName('total').slice(-1)[0].duration) | ||
// })() | ||
const BATCH_SIZE = 50; // Typically around 150ms for 6x slowdown in Chrome for above benchmark | ||
return dbPromise(db, STORE_EMOJI, MODE_READONLY, (emojiStore, cb) => { | ||
emojiStore.openCursor().onsuccess = e => { | ||
const cursor = e.target.result; | ||
let lastKey; | ||
if (!cursor) { // no more results | ||
cb(); | ||
} else if (predicate(cursor.value)) { | ||
cb(cursor.value); | ||
} else { | ||
cursor.continue(); | ||
} | ||
const processNextBatch = () => { | ||
emojiStore.getAll(lastKey && IDBKeyRange.lowerBound(lastKey, true), BATCH_SIZE).onsuccess = e => { | ||
const results = e.target.result; | ||
for (const result of results) { | ||
lastKey = result.unicode; | ||
if (predicate(result)) { | ||
return cb(result) | ||
} | ||
} | ||
if (results.length < BATCH_SIZE) { | ||
return cb() | ||
} | ||
processNextBatch(); | ||
}; | ||
}; | ||
processNextBatch(); | ||
}) | ||
@@ -334,0 +355,0 @@ } |
{ | ||
"name": "emoji-picker-element", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Lightweight emoji picker distributed as a web component", | ||
@@ -32,2 +32,4 @@ "main": "index.js", | ||
"benchmark:run-bundlesize": "bundlesize", | ||
"benchmark:storage": "PERF=1 run-s build:rollup && run-p --race test:adhoc benchmark:storage:test", | ||
"benchmark:storage:test": "node ./test/storage/test.js", | ||
"test:leak": "run-s build:rollup && run-p --race test:leak:server test:leak:test", | ||
@@ -90,2 +92,3 @@ "test:leak:server": "node ./test/leak/server.js", | ||
"focus-visible": "^5.2.0", | ||
"get-folder-size": "^2.0.1", | ||
"husky": "^4.3.6", | ||
@@ -100,2 +103,3 @@ "jest": "^26.6.3", | ||
"npm-run-all": "^4.1.5", | ||
"playwright": "^1.7.1", | ||
"postcss": "^8.2.1", | ||
@@ -185,3 +189,3 @@ "pretty-bytes": "^5.4.1", | ||
"path": "./bundle.js", | ||
"maxSize": "41 kB", | ||
"maxSize": "41.5 kB", | ||
"compression": "none" | ||
@@ -188,0 +192,0 @@ }, |
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
495227
5545
55