I want to store a maximum of around 10 thousand integers in sessionStorage. I will need to JSON parse and stringify to update this array of integers.
Is this a terrible idea? Or is the performance hit not too bad?
You shouldn't use SessionStorage for that purpose because it is blocking main thread that can leads to hanging your application.
Check IndexedDb instead
It designed to be async and more-less fast. And also it has pretty nice support:
https://caniuse.com/#search=indexeddb
Hope this helps
As @IrkenInvader said test and measure on your reference browser(eg. on low end mobile device parsing can be much slower).
A quick test:
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
var numbers = Array.apply(null, {length: 10000}).map(Function.call, (x) => getRandomInt(100));
var start = window.performance.now();
window.sessionStorage.setItem('test', JSON.stringify(numbers));
var end = window.performance.now();
console.log("timing", end-start);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With