-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance considerations: store only data as value #110
Comments
I think both options sounds reasonable, but I think I prefer 1. Sidenote, we need to ensure that @addyosmani thoughts? |
I vote for 1. |
Why? Maybe right away you have some ideas on how to deal with
My next step would be to send pull request so we would have something to look at. Though I doubt I would be able to do it during this week. |
Parsing out the key
We are.
Can you clarify? I'm not sure I see the original issue prompting this. |
Sure. When we store everything except data itself in the key the difficult part would be fetching the item we need. var map = {
'my-item': 'basket-my-item\t{url: "..."}'
}; |
You're assuming iteration is slow, but I don't really that's the case.
We do a regex for matching the key: |
Iteration itself is ok, splitting, splitting and checking is not so.
Indeed, we can even make it Sounds like a plan. This seems faster than my splitting option. |
Yup, sounds good to me. |
Right now in localStorage we have
basket-<key>
as key andJSON.stringify({ data: <script>, url: "...", expire: 5, etc: "..." })
as value.That as result means that we have to parse that object each time we want to check expiration time, etc. Sounds right. The problem here is in the fact that we also store scripts itself with the object. That as result means that stringified version of object could be really large and JSON.parse will not be fast.
In my case I've tried to store 3mb script file.
This file will expire only with the next application version. But what happens under the hood each time we load app?
We are calling basket.clear when basket is initialized which gets the item (parsing it), checks expire date and lets it live. Then we are calling require which once again calls get so we get item and parse it again, this time to use data.
The first parse is totally unnecessary in my case and the second could be simpler - we just need data of the script, without any processing.
So what I am suggesting?
I see following options:
basket-<key>-<JSON.strigify(props)>
and value would be just data.This way we always will be parsing small object with props and data will stay verbatim.
The downside - key just got complicated and then user invokes
basket.get('some.key');
we have to do more to find the element (iterate over all keys finding the one right). Some map can be used - specified key -> actual key.I am building specific prototype for my app and sort of (minus the map) implemented the first approach.
Please share your thoughts on this matter. If this sounds reasonable and useful we can discuss details and I could implement the solution.
The text was updated successfully, but these errors were encountered: