javascript - ng-repeat performance over thousands of elements without limit filter -
i'm generating svg graph in angular template based on array of following format:
[{x: 0, y: 1}, {x: 1, y: 2}, ...]
-- array contain thousands of points.
while can render <path>
element thousands of points, unacceptable performance occurs when use ng-repeat
create <circle>
element each point.
to ensure performance not due svg performance, copied angular generated svg output , created static .html file included 5 graphs containing 10,000 <circle>
elements. static file rendered instantly. confirmed it's not boiler plate code generating , scaling points because without <circle>
elements (only 2 <path>
elements) performance exceptional.
i've narrowed down either ng-repeat
's dom injection mechanics or fact ng-repeat
creates child scope each element own dirty checking watchers. based on exhaustive research appears it's more latter.
here's template generates graph:
<svg width="1020" height="220"> <g class="series" transform="translate(10,10)"> <path class="series-fill" d="{{ series.path('fill') }}" stroke="none" fill="#ddd"></path> <path class="series-path" d="{{ series.path('line') }}" stroke="#999" stroke-width="1" fill="none"></path> <g class="series-points" stroke-width="1" stroke="#fff"> <circle ng-repeat="point in points" class="series-point" r="2" cx="{{ point.scaledx }}" cy="{{ point.scaledy }}"></circle> </g> </g> </svg>
tl;dr, angular or recommended way use ng-repeat
-like behavior without dirty checking on each element or without creating new child scope watchers. paging/infinite scroll doesn't apply here.
Comments
Post a Comment