-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$http should coalesce calls to $apply #5297
Comments
@cmelion from HBO is also interested in a solution like this. |
The PR I'm working on introduces an $$applyAsync function to $rootScope. Calling it results in a timeout that will call apply. Repeated calls of it are coalesced into a single $apply. For starters, I'm calling it from $http, $evalAsync, and $cookies. |
I'll probably have it use a 0ms timeout. Increasing it does result in fewer apply calls in practice, but in my app, there's not much value to going above 10ms. I'd be fine using that too, but at some point we're slowing things down more than speeding them up. |
+1 |
14 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
@kseamon since this proposal was already approved for 1.3 you don't need to prefix it with |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
I'm willing to tackle this, if we are okay going ahead with it @IgorMinar ? |
I've got a PR in progress that I have not had a chance to work on in a while. If you want to start from scratch, make sure to cover these points: Implement $applyAsync on $rootScope. Make $http and $cookies use it. Make sure that regular $apply calls flush the queue and cancel the timeout. |
+1 |
1 similar comment
+1 |
@kseamon You could also push the branch to Github, if it's usable for further work. |
ping @kseamon |
Presently, $http calls $apply for every request response, even if they come in within milliseconds of each other. Using a short timeout (0ms, which in practice works out to 0-10ms) to $apply can reduce a lot of waste.
See example implementation here: https://github.com/kseamon/angular.js/compare/http-coalesce?expand=1
Using this code (Not ready for a pull request as it breaks tests and mocks, etc), I see the number of $apply calls in my app's startup drop from 40 to 16.
The text was updated successfully, but these errors were encountered: