JavaFx WebView Javascript changes eat up CPU

120 Views Asked by At

I have a project that is running AngularJs website inside an JFX webView. Whenever some javascript is running in a loop the CPU goes up to 100%. To be more specific I have a

 $scope.moveFloatingBanner = function () {
    try {

        var dx = $scope.activeFloatingBanner.startX - $scope.activeFloatingBanner.endX,
            dy = $scope.activeFloatingBanner.startY - $scope.activeFloatingBanner.endY,
            i = 1;

        function loop() {
            LogService.info("In lool");
            if ($scope.breakAnimation) {
                $scope.domElement.style.display = 'none';
                return;
            }
            if (i >= $scope.activeFloatingBanner.time) {
                $scope.domElement.style.display = 'none';
                $scope.changeFloatingBannerTimeout = $timeout($scope.changeFloatingBanner, $scope.activeFloatingBanner.nextDelay);
                return;
            }
            i += 1;
            $scope.domElement.style.left = ($scope.activeFloatingBanner.startX - (dx * i / $scope.activeFloatingBanner.time)).toFixed(0) + 'px';
            $scope.domElement.style.top = ($scope.activeFloatingBanner.startY - (dy * i / $scope.activeFloatingBanner.time)).toFixed(0) + 'px';
            $scope.moveBannerTimeout = $timeout(loop, 1);
        }

        loop();
    }
    catch (e) {
        LogService.error(e);
    }
}

This is the code responsible for moving a banner, This code has no issues when run in chrome or any other browser. Another part of code is responsible for updating a banner on the UI, it is a forever running timeout that retrieves new banner from the server every 10 seconds. When both of the loops are ran simultaneously the CPU goes up to 140%. The CPU-s that are run on are pretty weak and the UI starts lagging. When run on my local machine it does not lag but the GPU goes up to about 40-50%. When run without these 2 loops the CPU on the weak machine is about 6-7% and my local machine uses about 2% GPU. I am using oracle JDK 8 , java version "1.8.0_162-ea".

Any ideas what might be causing the issue? Maybe JFX version issue? JDK version?

0

There are 0 best solutions below