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.

21-Topaz I
July 8, 2022

if shoobject implies some call like this example:

name="model-1-/0/1/4"
if( isPreview())
 tml3dRenderer.GetObject(name).GetWidget().SetVisibility(true);
 else
 tml3dRenderer.setProperties(name,{ hidden:false} );

  then yes this requires time. In this case is better to set all properties and then call $scope.$applyAsync()

The question is also if you search is recursive - possibly your write to much things into stack

- I think for better performance you  can split the search and set. 

-first call the search and write all names of entities you want to set display  to a list (also disable any prints to console - this make it very slow). Later go sequentially and set in simple loop the properties of the entities. 

As mentioned this depends on you program and the size of the assembly and could be answered generally - and the point is that when we need to  change  the display of large numbers of  assembly parts -this  is something what still need time to refresh on mobile. There is not possible to use additional threads, I think