Skip to content

Comment on AngularJS Performance in Large Applications

Comments

Nit-pick, but I don't agree with his definitions of complexity.

>> The second reason software is slow is known as space complexity. This is a measure of how much 'space' or memory a computer needs to run your solution. The more memory required, the slower the solution.

Requiring more memory doesn't make an application slower by default. It simply means it requires more memory to run as expected.

Similarly, when he's talking about run time complexity, he calls it "a measure of how many comparisons a program needs to make to achieve a result". It can be any action, not necessarily a comparison. Be it number of times cycle needs to be executed, number of expensive calls to external service, etc. Number of comparisons to make is commonly used in introductory courses when studying sorting algorithm but doesn't make much sense without a context.

Also disagree with

  > 6.2 Watching Functions
  >
  > Another common problem is the utilization of functions
  > in watchers or bindings. Never bind anything (ng-show,
  > ng-repeat, etc.) directly to a function. Never watch
  > a function result directly. This function will run on
  > every digest cycle, possibly slowing your application
  > to a crawl. 
A while ago this sort of advice was true (when you'd see people inlining stuff in `eval` to avoid this), but nowadays function execution itself is very fast.

You don't want to watch a slow function, but just watching a function will not "[slow] your application to a crawl."

Interesting post, but I'd take this author's advice with some salt.

I disagree strongly as well. For example if you have something like ng-show="is_admin()" and $scope.is_admin = function() { return $scope.logged_in && $scope.role='admin' } or some other complexity reducing function, I don't understand how that would be significantly less performant than copying and pasting the return statement everywhere in your html.

Requiring more memory doesn't make an application slower by default.

On a cacheless system, that would be true. On a typical system with multilevel caches (and an application that does not fit completely in the smallest one), the number of cache misses will tend to go up as the memory usage increases, and that will affect performance. At the extreme end, when it's too big to fit completely in physical memory and the swapfile starts being used, the speed difference becomes night and day.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.