javascript - $scope.$apply slows down performance -


i have single page application using angularjs , facing 1 performance issue in it. application processes incoming events server side passed angularjs framework on client side using asp.net signalr. there millions of events can received application , there no performance issue on server side , passes these number of events 1 after other angularjs framework. problem lies on client side. after processing event, use $scope.$apply() update page , display events. in such case there multiple events being received 1 after other, calling $scope.$apply() every time slows down application , not show events quickly. events passed @ random don't know how events received application @ point in time.

any ideas on how issue resolved helpful.

thanks.

instead of using $scope.$apply(), use $scope.$evalasync() instead.

from docs:

executes expression on current scope @ later point in time.

the $evalasync makes no guarantees when expression executed, that:

  • it execute after function scheduled evaluation (preferably before dom rendering).
  • at least 1 $digest cycle performed after expression execution.

any exceptions execution of expression forwarded $exceptionhandler service.

note: if function called outside of $digest cycle, new $digest cycle scheduled. however, encouraged call code changes model within $apply call. includes code evaluated via $evalasync.

i tended have $scope.$safeapply() method debounced call $scope.$evalasync().


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -