Title: Performance solution
Last modified: September 28, 2019

---

# Performance solution

 *  Resolved [jmindl](https://wordpress.org/support/users/jmindl/)
 * (@jmindl)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/performance-solution/)
 * Hello,
    I would like to solve performance issues related to the multiple extensive
   calculations on the background.
 * **AS-IS status:**
    I have following settings on: 1. Enable autocompletion 2. 
   Eval dynamically the equations associated to the calculated fields
 * There are few hundreds of fields and many calculated once. When I click from 
   one to another there is a big slowness.
 * **Potential ideas how to solve this:**
    1. Any performance improvement of the
   code – unfortunately I am not so skilled enough to do it. Can do it via your 
   help as paid custom codding 2. Change settings to **untick** “Eval dynamically
   the equations associated to the calculated fields” – this will need to have button
   for calculate **No problem** **but** – current button field doesn’t reflect css
   code on the field as HTML content field with CP clocks. – I don’t know how to
   add HTML content field only to calculate not to submit. 3. Change to settings“
   Enable the browser’s persistence (the data are stored locally on browser)” **
   but** – There is a huge loading time
 * Can you please help me with one of these solutions?
 * Thanks
    Jaromir
    -  This topic was modified 6 years, 8 months ago by [jmindl](https://wordpress.org/support/users/jmindl/).
    -  This topic was modified 6 years, 8 months ago by [jmindl](https://wordpress.org/support/users/jmindl/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fperformance-solution%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/performance-solution/#post-11977683)
 * Hello [@jmindl](https://wordpress.org/support/users/jmindl/)
 * As you said, you have implemented a form with many calculated fields and many
   equations, and you have configured the form to evaluate the equations dynamically.
   That means to check all the equations every time a field varies its value to 
   identify the equations that are affected by this field, and then, after evaluate
   the equations, and as the value of the calculated fields vary (as result of the
   equations), the process is repeated until no field in the form varies its value.
 * There are different alternatives to solve the performance issue.
 * The first one would be optimize the equations and the number of calculated fields.
   Are you sure you need all of them? For example, if there are fields that are 
   used only to get intermediary values, why you don’t remove them, and implement
   more elaborated equations to use the original value?
 * For example, assuming you have a calculated field only to increase the value 
   of another field into a X%, to be uses in a third equation, why don’t remove 
   it, and apply the increment directly in the final equation?
 * Another solution would be disable the dynamic evaluation of the equations, and
   evaluate the equations pressing a button (selecting the “calculate” option as
   the button’s type). If you are inserting the buttons using the “CP Blocks” plugin,
   assign the special class name: `calculate-button` to this button.
 * Third alternative, to improve the performance of the form’s generation, implement
   a lazy evaluation of the equations.
 * – Untick the checkbox to evaluate the equations dynamically,
    – And then, insert
   into the form a “HTML Content” field with the following piece of code as its 
   content:
 *     ```
       <script>
       fbuilderjQuery(document).one('showHideDepEvent', function(){
       setTimeout(function(){
       fbuilderjQuery('[id*="cp_calculatedfieldsf_pform_"]').attr('data-evalequations',1);
       fbuilderjQuery.fbuilder.calculator.defaultCalc('#cp_calculatedfieldsf_pform_2');
       }, 2000);
       });
       </script>
       ```
   
 * Best regards.
 *  Thread Starter [jmindl](https://wordpress.org/support/users/jmindl/)
 * (@jmindl)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/performance-solution/#post-11977942)
 * Thanks a lot for great a very quick response.
    If I will combine the calculation
   into the one of the extensive calculated field and not use the intermediate field
   I need to work with variable, which I will use for displaying in the summary
 * I have following piece of codes (currenty in many of the fields) which need to
   go to be combined
 * **fieldname457**
 * (function(){
 * if(fieldname444 == 1) return prec(fieldname443,0);
    if(fieldname444 == 2) return
   round(fieldname443/6); if(fieldname444 == 3) return round(fieldname443/12); })();
 * **fieldname458**
 * (function(){
 * if(fieldname447 == 1) return prec(fieldname448,0);
    if(fieldname447 == 2) return
   round(fieldname448/6); if(fieldname447 == 3) return round(fieldname448/12); })();
 * **fieldname459**
 * (function(){
 * if(fieldname453 == 1) return prec(fieldname454,0);
    if(fieldname453 == 2) return
   round(fieldname454/6); if(fieldname453 == 3) return round(fieldname454/12); })();
 * **fieldname464**
 * (function(){
 * if(fieldname462 == 1) return prec(fieldname463,0);
    if(fieldname462 == 2) return
   round(fieldname463/6); if(fieldname462 == 3) return round(fieldname463/12); })();
 * **fieldname469**
 * (function(){
 * if(fieldname467 == 1) return prec(fieldname468,0);
    if(fieldname467 == 2) return
   round(fieldname468/6); if(fieldname467 == 3) return round(fieldname468/12); })();
 * **fieldname474**
 * (function(){
 * if(fieldname472 == 1) return prec(fieldname473,0);
    if(fieldname472 == 2) return
   round(fieldname473/6); if(fieldname472 == 3) return round(fieldname473/12); })();
 * **fieldname479**
 * (function(){
 * if(fieldname477 == 1) return prec(fieldname478,0);
    if(fieldname477 == 2) return
   round(fieldname478/6); if(fieldname477 == 3) return round(fieldname478/12); })();
 * **fieldname484**
 * (function(){
 * if(fieldname482 == 1) return prec(fieldname483,0);
    if(fieldname482 == 2) return
   round(fieldname483/6); if(fieldname482 == 3) return round(fieldname483/12); })();
 * **fieldname489**
 * (function(){
 * if(fieldname487 == 1) return prec(fieldname488,0);
    if(fieldname487 == 2) return
   round(fieldname488/6); if(fieldname487 == 3) return round(fieldname488/12); if(
   fieldname487 == 4) return round(fieldname488/36); })(); `
 * If I need to use these pieces and calculate them all together, like:
 * `fieldname457+fieldname458+fieldname459+fieldname464+fieldname469+fieldname474
   +fieldname479+fieldname484+fieldname489`
 * How the final code would looks like?
 * Thanks
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/performance-solution/#post-11977963)
 * Hello [@jmindl](https://wordpress.org/support/users/jmindl/)
 * All these equations can be implemented as only one equation as follows:
 *     ```
       (function () {
       	var result = 0, factor = 1;
       	switch(fieldname444)
       	{
       		case 1: factor = 1; break; 
       		case 2: factor = 6; break; 
       		case 3: factor = 12; break; 
       	}
       	result += fieldname443/factor;
   
       	factor = 1;
       	switch(fieldname447)
       	{
       		case 1: factor = 1; break; 
       		case 2: factor = 6; break; 
       		case 3: factor = 12; break; 
       	}
       	result += fieldname448/factor;
   
       	factor = 1;
       	switch(fieldname453)
       	{
       		case 1: factor = 1; break; 
       		case 2: factor = 6; break; 
       		case 3: factor = 12; break; 
       	}
       	result += fieldname454/factor;
   
       	factor = 1;
       	switch(fieldname462)
       	{
       		case 1: factor = 1; break; 
       		case 2: factor = 6; break; 
       		case 3: factor = 12; break; 
       	}
       	result += fieldname463/factor;
   
       	factor = 1;
       	switch(fieldname467)
       	{
       		case 1: factor = 1; break; 
       		case 2: factor = 6; break; 
       		case 3: factor = 12; break; 
       	}
       	result += fieldname468/factor;
   
       	factor = 1;
       	switch(fieldname472)
       	{
       		case 1: factor = 1; break; 
       		case 2: factor = 6; break; 
       		case 3: factor = 12; break; 
       	}
       	result += fieldname473/factor;
   
       	factor = 1;
       	switch(fieldname477)
       	{
       		case 1: factor = 1; break; 
       		case 2: factor = 6; break; 
       		case 3: factor = 12; break; 
       	}
       	result += fieldname478/factor;
   
       	factor = 1;
       	switch(fieldname482)
       	{
       		case 1: factor = 1; break; 
       		case 2: factor = 6; break; 
       		case 3: factor = 12; break; 
       	}
       	result += fieldname483/factor;
   
       	factor = 1;
       	switch(fieldname487)
       	{
       		case 1: factor = 1; break; 
       		case 2: factor = 6; break; 
       		case 3: factor = 12; break; 
       	}
       	result += fieldname488/factor;
   
       	return round(result);	
       })()
       ```
   
 * Best regards.
 *  Thread Starter [jmindl](https://wordpress.org/support/users/jmindl/)
 * (@jmindl)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/performance-solution/#post-11978002)
 * Absolutely briliant, thanks a lot

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Performance solution’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [jmindl](https://wordpress.org/support/users/jmindl/)
 * Last activity: [6 years, 8 months ago](https://wordpress.org/support/topic/performance-solution/#post-11978002)
 * Status: resolved