Skip to content
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

improve performance by not to save/load the whole data everytime #31

Closed
beeplin opened this issue Nov 5, 2016 · 2 comments
Closed

improve performance by not to save/load the whole data everytime #31

beeplin opened this issue Nov 5, 2016 · 2 comments

Comments

@beeplin
Copy link

@beeplin beeplin commented Nov 5, 2016

It seems that each time we read/write to this service, it load/save the whole big string from localstorage, which might lead to big performance problem when the string is very very long.

It could be improved by not to save all data into a single localstorage item name, but to save different items based on each record's id. Then we just need to call localstorage.getItem(id) to get, and localstorage.setItem(id) to create/update/patch, localstorage.removeItem(id) to remove.

BTW, we could also consider making an interface for localforage, a wrapper and extension for localstorage.

@daffl

This comment has been minimized.

Copy link
Member

@daffl daffl commented Nov 5, 2016

The reason is that the adapter can rely on feathers-memory for everything except for writing and reading from localStorage. Writes are throttled so if you make 100 changes at once it will only cause one write. The adapter also only reads from localStorage once during initialization. I would argue that it is in general probably faster than writing and reading individual items from localStorage every time.

If you are still concerned about write performance you can set the throttle option from the default of 200ms to a higher value, e.g. 5000 which will only write every 5 seconds (if anything changed at all).

@beeplin

This comment has been minimized.

Copy link
Author

@beeplin beeplin commented Nov 6, 2016

yes that makes sense. Localstorage itself has very limited data size, so loading the whole thing into memory should be OK. :)

@beeplin beeplin closed this Nov 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.