$http should coalesce calls to $apply
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.
@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
+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 $$ use $ in your PR instead.
+1