You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I got a big JSON file (35MB), which took around 7 ms to fetch and 1000 ms to parse. I'm thinking of storing objects to minimize the parse time. I tried localforage, and found that it took roughly 900 ms to get it from the storage? I thought storing/retrieving JSON objects should not take long, but it seems that I was wrong. I explicitly set the driver to indexeddb just in case.
async loadJsonFile(filePath, hasData = false) {
if (hasData) {
let start_time = Date.now();
localForage.setDriver([localForage.INDEXEDDB]);
let jsonObjects = await localForage.getItem(filePath);
if (jsonObjects) {
let end_time = Date.now();
console.log ("localForage took ", (end_time - start_time), " ms");
return jsonObjects;
}
}
let start_time = Date.now();
const response = await fetch(filePath);
if (!response.ok) {
return null;
}
let end_time = Date.now();
console.log ("fetch took ", (end_time - start_time), " ms ")
start_time = Date.now();
let jsonObjects = await response.json();
end_time = Date.now();
console.log ("parse took ", (end_time - start_time), " ms ")
localForage.setDriver([localForage.INDEXEDDB]);
localForage.setItem(filePath,jsonObjects);
return jsonObjects;
}
first run:
fetch took 7 ms
parse took 1047 ms
subsequence run:
localForage took 956 ms
I looked at IndexedDB in the Dev console, and it was actually stored at JSON objects (not JSON string). I wonder why it took long to retrieve data from IndexedDB?
Is there anyway to use localforage to retrieve the JSON objects faster?
The text was updated successfully, but these errors were encountered:
I got a big JSON file (35MB), which took around 7 ms to fetch and 1000 ms to parse. I'm thinking of storing objects to minimize the parse time. I tried localforage, and found that it took roughly 900 ms to get it from the storage? I thought storing/retrieving JSON objects should not take long, but it seems that I was wrong. I explicitly set the driver to indexeddb just in case.
async loadJsonFile(filePath, hasData = false) {
}
first run:
fetch took 7 ms
parse took 1047 ms
subsequence run:
localForage took 956 ms
I looked at IndexedDB in the Dev console, and it was actually stored at JSON objects (not JSON string). I wonder why it took long to retrieve data from IndexedDB?
Is there anyway to use localforage to retrieve the JSON objects faster?
The text was updated successfully, but these errors were encountered: