What are the disadvantages of $http.useApplyAsync?


I am currently exploring $http in angularjs, and I've seen this super-amazing method: useApplyAsync which will synchronize my $http requests, and will make my app faster.

All good, but why by default angularjs is setting it to false? Are there any disadvantages of using it?


I also made a comparison between using useApplyAsync and not using it.

Here I used it: http://jsfiddle.net/vwnLz344/17/ Here I didn't use it: http://jsfiddle.net/vwnLz344/18/

I am unable to see the advantages of it...

What I am searching for is: The Advantages and the Disadvantages of: useApplyAsync

Show source
| javascript   | angularjs   2017-01-04 08:01 1 Answers

Answers to What are the disadvantages of $http.useApplyAsync? ( 1 )

  1. 2017-01-04 09:01

    Probably doesn't make a huge difference with a smaller app - by the sounds of things useApplyAsync will delay processing by ~10ms but aggregates processing of responses so may be slightly faster if say multiple responses come in within that window it might allow them to share a digest cycle avoiding extra overheads.

    The default behavior processes each individual response more quickly (I think synchronously) but might require more digest cycles if multiple responses are received in quick succession which might require more processing and hence be slower overall.

    So short answer useApplyAsync is probably faster with many rapid requests that update a lot of data, the default behavior is probably faster with less frequent requests.

    I'd guess that it's disabled by default as usually if you're firing off that many AJAX requests you probably need to rethink your API (ie provide options for consolidating the requests).

    Advantages of enabling useApplyAsync

    If multiple responses are received in short succession it might reduce the amount of digest cycles required

    Disadvantages of enabling useApplyAsync

    It may delay processing of a response by ~10ms whilst waiting to aggregate processing

    Why is it disabled by default?

    Delaying processing of most AJAX requests by ~10ms for a short window to attempt to process multiple responses concurrently and avoid additional digest cycles is for most use cases less desirable than the few additional digest cycles it might save by enabling it.

    The relevant docs have more info



    "Configure $http service to combine processing of multiple http responses received at around the same time via $rootScope.$applyAsync. This can result in significant performance improvement for bigger applications that make many HTTP requests concurrently (common during application bootstrap). "



    Schedule the invocation of $apply to occur at a later time. The actual time difference varies across browsers, but is typically around ~10 milliseconds.



    $apply() is used to execute an expression in angular from outside of the angular framework. (For example from browser DOM events, setTimeout, XHR or third party libraries). Because we are calling into the angular framework we need to perform proper scope life cycle of exception handling, executing watches.

Leave a reply to - What are the disadvantages of $http.useApplyAsync?

◀ Go back