Improving Performance

Overview

The JavaScript code in a variable dependency or interval expression is executed when the page is opened and with each change to the page (e.g. entering a variable's data).  If a significant amount of JavaScript code is executed, it can reduce the responsiveness of the browser.

Options

Some options to keep the responsiveness of the browser from being reduced:

  • Adding a page break between variable groups to increase the speed as only the code on each page is executed (see the Layout tab on the Variable Group Update page).
  • Utilizing local variables in place of repeating a condition with a StudyTRAX Variable.
  • Implementing a global variable to track the current state, thus hiding or disabling will be executed only if the state changes.  To implement a global variable, set the global variable before the main function. 

    A StudyTRAX variable cannot be used as a global variable before the main function.

Examples

Utilize local variables

It takes fewer operations to evaluate the value of a local variable than it takes to evaluate the value of a StudyTRAX variable

Instead of:

Do:

#variable1.show(#myVar1==1);
#variable2.show(#myVar1==1);
#variable3.show(#myVar1==1);
#variable4.show(#myVar1==1);
#variable5.show(#myVar1==1);

var myResult = #myVar1==1 ? true : false;
  #variable1.show(myResult);
  #variable2.show(myResult);
  #variable3.show(myResult);
  #variable4.show(myResult);
  #variable5.show(myResult);

#variable11.show(#myVar2==1);
#variable12.show(#myVar2==2);
#variable13.show(#myVar2==3);

var myResult2=#myVar2;
  #variable11.show(myResult2==1);
  #variable12.show(myResult2==2);
  #variable13.show(myResult2==3);



 Utilize global variables

A global variable can be used if a large number of variables are being hidden or disabled based on one condition

Instead of:

Do:

function main() {

#variable21.show(#myVar3==1);
#variable22.show(#myVar3==1);
#variable23.show(#myVar3==1);
#variable24.show(#myVar3==1);
etc.
}

var areVarsShown=true;

function main() {
  showMyVars(#myVar3==1);
}

function showMyVars(doShow) {
  if (doShow==areVarsShown) return;   // if no change, do not execute the remaining code
    areVarsShown=doShow;                // change the value of the global variable

   #variable21.show(doShow);
   #variable22.show(doShow);
   #variable23.show(doShow);
   #variable24.show(doShow);
   etc.
}