angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

$http should coalesce calls to $apply

Open kseamon opened this issue 12 years ago • 30 comments

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.

kseamon avatar Dec 05 '13 20:12 kseamon

+1

isamulenko avatar Dec 18 '13 10:12 isamulenko

+1

aroop avatar Dec 20 '13 16:12 aroop

+1

jkerkhofs avatar Dec 28 '13 12:12 jkerkhofs

+1

saydogan avatar Dec 28 '13 12:12 saydogan

I'm willing to tackle this, if we are okay going ahead with it @IgorMinar ?

thebigredgeek avatar Jan 23 '14 18:01 thebigredgeek

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.

kseamon avatar Jan 23 '14 20:01 kseamon

+1

abirmingham avatar Jun 04 '14 01:06 abirmingham

+1

filso avatar Jun 25 '14 09:06 filso

@kseamon You could also push the branch to Github, if it's usable for further work.

Narretz avatar Jun 25 '14 12:06 Narretz

ping @kseamon

timelf123 avatar Jul 09 '14 17:07 timelf123