Closed fspoettel closed 5 months ago
Thanks! I'll take a look at this.
Hm, on both Chrome and Firefox the autosave never takes more than 10ms, regardless of whether the database is there or not beforehand.
The autoLoad seems to be the problem.
OK, just documenting the analysis here. All with no database present:
console.time('save');
persister.save().then(() => {
console.timeEnd('save'); // fast
});
console.time('load');
persister.load().then(() => {
console.timeEnd('load'); // fast
});
BUT...
console.time('load');
persister.load().then(() => {
console.timeEnd('load');
console.time('save');
persister.save().then(() => console.timeEnd('save')); // slow
});
and yet...
console.time('save');
persister.save().then(() => {
console.timeEnd('save');
console.time('load');
persister.load().then(() => console.timeEnd('load')); // fast
});
🤔
I think I have a fix. The connection is not closed when the first load fails, so the save has to wait for it to timeout.
OK, the fix is in v4.6.1. Wanna try it out?
Assuming it's all good, closing out.
hey sorry, forgot to answer. yes, it's fixed on my end as well. thanks! :)
Describe the bug
I'm running the issue that initializing the IndexedDB persister is very slow, while it's fast on subsequent loads:
I thought this was IndexedDB being slow, but I then switched to pre-creating the database with the same layout tinybase expects and the whole thing is then very fast consistently in both cases:
The init function does this:
The
ensureDatabase
function does this:The slowdown seems to be caused by awaiting
startAutoSave
, it might be something related to the scheduling logic, I'm not sure though.Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
Create an
indexedDBPersister
and time how long it takes untilstartAutoSave
resolves.Expected behavior
No response
Screenshots or Videos
No response
Platform
Additional context
No response