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
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This does not explain why the calculated field is so slow. How did you measure performance?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.