Skip to main content
15-Moonstone
July 6, 2022
Question

FPS drop during computing

  • July 6, 2022
  • 1 reply
  • 2978 views

Hi, I want to share a possible problem in my AR experiences. When there is a heavy data iteration (eg for loop through JSON metadata) while running the experience, the FPS goes very low.

How can I solve it?

1 reply

21-Topaz I
July 7, 2022

Hi @GianVal ,

the question is what kind of iteration is it - I think such behavior could be  normal if you do any iteration steps in nearly infinity loop.

So what you can do if the loop is doing some calculation which are not directly affecting widgets properties and display then you can try to call the calculation to second thread - e.g. 

https://medium.com/jspoint/achieving-parallelism-in-javascript-using-web-workers-8f921f2d26db

https://www.w3schools.com/html/html5_webworkers.asp

https://web.dev/workers-basics/#toc-inlineworkers

 

Another points is to call in each iteration the call

$scope.$applyAsync();

or to call each iteration as function with $timeout service with / or without delay

So for example you can try something like this:

let myDelayPerItterationCall = 100; //so 100 millisecond per call delay
for(let i=0; i< verylargeNumber; i++)
{
$timeout(()=>{ 
 myFunction1();
 ....
 myFunctionN();
 $scope.$applyAsync(); 
 }, myDelayPerItterationCall *i) //end timeout call
} //end for loope

 

GianVal15-MoonstoneAuthor
15-Moonstone
July 7, 2022

I apply a "showobject" method to ALL the parts of my structure. To do this I perform a for loop on the entire model metadata structure. 

I know that is a huge computational load, but I will investigate on webworkers solution.

I tried with $scope.$applyAsync() and timeout method but they don't work.

GianVal15-MoonstoneAuthor
15-Moonstone
July 8, 2022

Another way I could experiment is to monitor the FPS and show a sort of "loading" modal popup while the FPS is under a certain threshold. Do you know how to monitor the current FPS of the experience?