{"action":"closed","issue":{"url":"https://api.github.com/repos/christopherthielen/ui-router-extras/issues/117","labels_url":"https://api.github.com/repos/christopherthielen/ui-router-extras/issues/117/labels{/name}","comments_url":"https://api.github.com/repos/christopherthielen/ui-router-extras/issues/117/comments","events_url":"https://api.github.com/repos/christopherthielen/ui-router-extras/issues/117/events","html_url":"https://github.com/christopherthielen/ui-router-extras/issues/117","id":51374927,"number":117,"title":"Sticky State Performance: Too Many Watchers","user":{"login":"vahan-hartooni","id":5114690,"avatar_url":"https://avatars.githubusercontent.com/u/5114690?v=3","gravatar_id":"","url":"https://api.github.com/users/vahan-hartooni","html_url":"https://github.com/vahan-hartooni","followers_url":"https://api.github.com/users/vahan-hartooni/followers","following_url":"https://api.github.com/users/vahan-hartooni/following{/other_user}","gists_url":"https://api.github.com/users/vahan-hartooni/gists{/gist_id}","starred_url":"https://api.github.com/users/vahan-hartooni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vahan-hartooni/subscriptions","organizations_url":"https://api.github.com/users/vahan-hartooni/orgs","repos_url":"https://api.github.com/users/vahan-hartooni/repos","events_url":"https://api.github.com/users/vahan-hartooni/events{/privacy}","received_events_url":"https://api.github.com/users/vahan-hartooni/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/christopherthielen/ui-router-extras/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/christopherthielen/ui-router-extras/labels/stickystate","name":"stickystate","color":"eb6420"},{"url":"https://api.github.com/repos/christopherthielen/ui-router-extras/labels/wontfix","name":"wontfix","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-12-09T01:01:23Z","updated_at":"2015-01-07T19:54:13Z","closed_at":"2015-01-07T19:54:13Z","body":"The sticky state extra was based on the tab use case, however the app will slow down when there are too many tabs. \r\n\r\nI looked into how [sticky state example](http://christopherthielen.github.io/ui-router-extras/example/sticky/index.html) was achieved and I see that the view and scope is retained by hiding the ui-view containers instead of swapping out templates. However, there is a glaring performance issue with this strategy: since the scope is retained, so are the watchers. In the example, run [this snippet](https://gist.github.com/kentcdodds/31c90402750572107922#file-get-watchers-js) in the console to get the number of watchers in the page. You'll notice that as you dive deep into each state, the number of watchers goes up. You can imagine how this can be an issue on a production tab system where some of those tabs might have a thousand entry table!\r\n\r\nTo have a performant tab system, the $$watchers inside the hidden views (inactive states) would need to be \"paused.\" Unfortunately, Angular has no way of doing this. I propose that when we leave an active state, Sticky State will go through the state's scope, remove and store all the $$watchers in a separate tree structure. When we return to that state, the $$watchers are reapplied to the active state's scope. \r\n\r\nDoes anyone foresee any problems with this proposal? \r\n\r\nAre there any alternative ways we can prevent Angular from checking the watchers in the inactive states?"}}