So I have this rather large application built on angular, alot of nested states, alot of directives, data tables and stuff.
We recently decided to switch to full single page, instead of having few small single apps sections(say articles, people, dashboard were each a small single page app previously), so I started dealing with performance a bit more. In chrome you don't visually notice a thing, on firefox on the other hand I THINK it becomes slower over time.
So I started with three snapshot technique to see what's up. But I'm not entirely sure what to make of it.
- snapshot size doubles its size each snapshot taken(1st 15mb, 2nd 67mb, 3rd 120mb), does this mean anything?
- there's a LOT of red dom, 4000 of red divs for example
Now I feel that those red divs, spans and anchors are mainly my fault, I'm doing some not-so-usual stuff to render those data tables, using this directive I made, and I also feel that some of heap objects are result of those dom elements not being removed properly.
This is what the table directive essentially does
var rows = '<div class="row" ng-repeat="item in items">';
_.each(columns, function(column) {
// pass cell as a string from $templateCache, instead of having <table-cell type="column.type"> which loaded correct templateUrl depending on what was passed via type attr
var cellTemplate = $templateCache.get(column.type);
rows += '<div class="column">' + cellTemplate + '</div>';
});
rows += '</div>';
// el is from directive link function
el.html(rows);
$compile(el.contents())(scope);
Reason why I'm doing this at all is because when I tried to use nested ng-repeat
for rows and columns and <table-cell>
directive for cells, it took way too long to render, even with only about 6 columns and 50 rows.
So what I think is happening is that none of those divs inside this table gets removed properly so they keep stacking up everytime this table directive loads.
Now even if I deal with that detached dom tree.. what about all the other stuff, how do I know which I should try and deal with, and which are usual for angular and doesn't really affect the performance?
// edit table directive on plunker http://plnkr.co/edit/1fZi6mVn2jBIGF0Q2a40?p=preview