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

Store causing huge memory retention and cleanup takes forever #573

Open
anshul-kai opened this issue Jul 7, 2016 · 2 comments
Open

Store causing huge memory retention and cleanup takes forever #573

anshul-kai opened this issue Jul 7, 2016 · 2 comments

Comments

@anshul-kai
Copy link

I have an extremely large application (over 40k lines of code) which heavily relies on backbone relational. Using backbone relational has certainly come in handy in many regards but we are soon realizing that there seems to be a huge price to pay for large applications. I'm writing this with the hopes that my realization is wrong.

One of our bigger Models often ends up in a Tree structure with over 10k child nodes. This Tree has more than 10 levels of nestings with each child node representing a unique Model or a Collection. The problem at hand is a major memory retention that happens due to the Store.

Following are the approaches I've tried with results noticed:

  1. Perform a deep cleanup - Iterate through the whole Tree calling Backbone.Relational.store.unregister on each model. This works but sometimes takes minutes to complete which is completely unacceptable from a user experience perspective.
  2. Backup the Store before loading the Tree and restore it to its original state. I've also tried unregistering all new Collections inspired by the Store.reset function. This approach seems to work unreliably and seems extremely hacky.
  3. Introducing a new scope by using addModelScope and removeModelScope. This seems to have no affect and if my understanding is correct, the model scope is set only for definitions and not instances.

Is there no graceful way to perform a memory cleanup?

@kjantzer
Copy link

This doesn't solve your problem, but I had the same issue.

Backbone relational started off as a nice feature that sped up development, but quickly became a bog on performance. Over the last couple of years I've migrated all my collections and models to my own plugin that helps manage relations between collections and models.

Check out Backbone Child Collections

Child collections/models are not instantiated until accessed and even then remain lightweight by not creating a bunch of event bindings

Children can be accessed via get(key) just like attributes and children have access to the parent via collection or parentModel.

@nightsurge
Copy link

@a-koka I know this is an old issue, but one thing that REALLY helped for us, was to set the "includeInJSON" attribute of the reverseRelation to false. It is default by true, which was causing a super crazy large nested object as we used the toJSON method when setting up data for our views.

We went from 2.5GB of RAM for this one larger page, to 30MB.... that's how crazy the nested-ness can get.

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

3 participants