My application is consuming a lot of data per second. We use $watch Method a lot in our screens. But especially in one of them, we use it around 20 different times. I have read that $scope.$watch
is impacting performance, so my questions are the following:
1. If that is true. The fact that $watch
has a performance penalty?
2. With what may I substitute it with?
Here is a small sample of the code we use. Note that this code is 3 years + old.
CTRL.JS File:
$scope.$watch("pageDataItemsPerPage.num", () => {
ctrl.setMaxPageData($scope.pageDataItemsPerPage.num);
});
or another one:
$scope.$watch(() => this.Keywords, (keywords) => {
$scope.hintOptions = Object.assign({}, $scope.hintOptions, { keywords });
});
$scope.$watch(() => this.tables, (tables) => {
$scope.hintOptions = Object.assign({}, $scope.hintOptions, { tables });
});
I understand, that the process for each one would be different but I don't know AngularJS really well, and I want some guidance. Also as a ref, just in this file, we use $scope.$watch over 30 times
.
If you could transform those 3 using ES6+ methods instead of angular ones would be great.
Regarding Performance:
It appears a lot of the performance issues are happening due to the $scope.$watch function, to my untrained eye at least don't seem the problem. The main thing is according to my investigation, RxJS and dispatching events on the fly. Not sure what can be done here though.