Skip to content

Performance with AngularJS #15

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

Closed
radarfox opened this issue Nov 24, 2015 · 3 comments
Closed

Performance with AngularJS #15

radarfox opened this issue Nov 24, 2015 · 3 comments

Comments

@radarfox
Copy link

Hello Jason,

I think there is a big performance problem in part of this adapter when using with AngularJS.

If you are calling create or destroy on many items (thousands), you end up with $rootScope.$apply for every item, and huge lags!

Why?

  1. In this adapter setTimeout is called for every injected item here https://github.com/js-data/js-data-localstorage/blob/master/src/index.js#L44
  2. In each of timeout execution inject for that item is invoked
  3. And then js-data-angular call $apply as reaction on that https://github.com/js-data/js-data-angular/blob/master/src/index.js#L199

I have replaced setTimeout for sync callback as hotfix, but I am not sure if thats good.

@jmdobry
Copy link
Member

jmdobry commented Nov 24, 2015

Thanks for bringing this up. There are a couple ways to deal with this at the moment:

  • Don't use js-data-angular, but instead use js-data directly, as js-data is not coupled to Angular's $digest loop.
  • Use destroyAll instead of destroy to delete many items at once.
  • Keep your using hotfix, though I'm not sure about its implications
  • Write a batch create method yourself, until one can be added to js-data-localstorage

I am planning to add a batch create method that can create many items at once.

@radarfox
Copy link
Author

  • Not using js-data-angular is kind of extreme solution. I would miss other usefull features as $http integration.
  • destroyAll is not helping, as it simply calls destroy on each item with no performance optimalizations https://github.com/js-data/js-data-localstorage/blob/master/src/index.js#L386
  • What do you mean by "batch create"? Something like implementating new function createAll (similar to deleteAll)? Wouldnt that required modifications to the core js-data module?

@jmdobry
Copy link
Member

jmdobry commented Nov 24, 2015

destroyAll is not helping, as it simply calls destroy on each item with no performance optimalizations

Oh yeah, I forgot. Other adapters that connect to actual databases are able to optimize this method. localStorage doesn't have any collection-based operations.

What do you mean by "batch create"? Something like implementating new function createAll (similar to deleteAll)?

Something like this: User.createMany([{ name: 'Bob' }, { name: 'John' }])

Wouldnt that required modifications to the core js-data module?

Yes, but only if you want to be able to call DS#createMany. Adapters can be used directly when necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants