Performance Problems Calculated Number Fields

Andreas Kundert December 23, 2015

We have a calculation based on different custom fields to show the business value of an issue. sadly the formula is not very performant. the formula is:

<!-- @@Formula:
//Constants
var a = 0.3; // Strategical alignment (sa) and Revenue potential (rp) are weighted 30%
var b = 0.2; // Saving potential (sp) and competitive advantage (ca) are weighted 20%
var x = 2; // Is the factor for the weight of "business value" (bv) in the model
var y = 1; // Is the factor for the weight of the "loss of value" (lv) in the model
var z = 1; // Is the factor for the weight of the "capacity increase" (ci) in the model
//Variables for business value
int sa = (issue.get("customfield_11631") != null ? Integer.parseInt(issue.get("customfield_11631").toString()) : 0);
int rp = (issue.get("customfield_11632") != null ? Integer.parseInt(issue.get("customfield_11632").toString()) : 0);
int sp = (issue.get("customfield_11633") != null ? Integer.parseInt(issue.get("customfield_11633").toString()) : 0);
int ca = (issue.get("customfield_11634") != null ? Integer.parseInt(issue.get("customfield_11634").toString()) : 0);
var bv = (sa+rp)*a + (sp+ca)*b;
//Variables for loss of value over time
int lv = (issue.get("customfield_11635") != null ? Integer.parseInt(issue.get("customfield_11635").toString()) : 0);
//Variables for capacity increase
int ci = (issue.get("customfield_11636") != null ? Integer.parseInt(issue.get("customfield_11636").toString()) : 0);
//Variables for investment
int in = (issue.get("customfield_11637") != null ? Integer.parseInt(issue.get("customfield_11637").toString()) : 0);
//WSJF calculation
var wsjf = (x*bv + y* lv+ z*ci)/in;

return wsjf;

-->

we thought about converting it to something like:

<!-- @@Formula:
function q(e){return
issue.get(e)?+(issue.get(e)+""):0}return(2*((q("customfield_11631")+q("customfield_11632"))*.3+(q("customfield_11633")+q("customfield_11634"))*.2)+1*q("customfield_11635")+1*q("customfield_11636"))/q("customfield_11637");
-->

 

But then it's not working an the log is full of errors because obviously characters like the + or functions are not allowed.

Is there a solution to raise the performance or a documentation what kind of script (it's not real javascript, right?) we can try to use instead?

 

thanks in advance 

 

 

1 answer

1 vote
David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 23, 2015

First of all, the syntax supported in Calculated Field formulas is BeanShell. It supports creating classes and methods, just like the Java language it closely resembles.

Then, how did you find out that you had performance issues? 

One very easy way to double performance would be to store the value of each field you are referencing in a variable instead of accessing it twice using issue.get(). For example:

var val = issue.get("customfield_11631");
int sa = (val != null ? Integer.parseInt(val.toString()) : 0);

Then, another cause of performance issues could be related to the fields you are accessing in the formula. What type of fields are they?

Andreas Kundert December 23, 2015

thanks for the hint with the double access by using issue.get twice. going to try that out. the fields we use are configurated as a select list (single choice) = dropdowns with numbers 1-10

David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 24, 2015

This does not explain why the calculated field is so slow. How did you measure performance?

Andreas Kundert January 3, 2016

Measured it with Chrome Console - the Jira page loads fine within 1.3-1.9s but then there is a gap until Jira Agile Content is loaded and viewable around 8-9s. See Answer below with the screenshot.

David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 4, 2016

I don't see the Answer below with the screenshot... Also, if you try to modify the formula to just "return 1;" , does it solve your performance issue? If not, then it means the problem does not lie with this custom field...

Suggest an answer

Log in or Sign up to answer