I need help with optimizing the performance of my app that retrieves json data. The json file contains nearly one thousand words structured like this:
{"THEMES":{"THEME1":["ITEM1","ITEM2","ITEM3"],"THEME2":["ITEM1",...]...}}
The size of the file is around 25kb. In a specific part of my application, I have to match each ITEM with its corresponding THEME in order to display a selected item related to a word using angular ng-repeat. Below is the section of my angular code that handles this functionality:
<div class="well">
<div class="input-group" bindonce ng-repeat="word_in_list in words_list">
<div class="form-group">
<select>
<option ng-selected="word_in_list.select == theme" ng-repeat="theme in themes" value="{{theme}}">{{theme}}</option>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="{{word_in_list.input}}">
<span class="input-group-addon">
<input type="checkbox" ng-click="listControlWord($event, word_in_list.input, word_in_list.select)">
</span>
</div>
</div>
</div>
The crucial part lies here:
$http.get('json/word_bank.json')
.success(function (result) {
$scope.themes = Object.keys(result.THEMES);
for (var i = 0, z = $scope.themes.length; i < z; i++) {
for (var j = 0; j < result.THEMES[$scope.themes[i]].length; j++) {
$scope.words_list.push({select: $scope.themes[i], input: result.THEMES[$scope.themes[i]][j]});
}
}
});
The problem is that browser rendering takes too long, sometimes crashing the browser due to the excessive time taken. Despite the loops functioning correctly and data retrieval being successful, the slow rendering speed is not acceptable. What can I do to optimize these loops?