# calculation execution and relation performance

**URL:** <https://forum.servoy.com/t/calculation-execution-and-relation-performance/15322>\
**Category:** Classic Servoy\
**Created:** [January 11, 2012, 9:03am UTC](https://forum.servoy.com/t/calculation-execution-and-relation-performance/15322 "2012-01-11T09:03:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgs](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@tgs](https://forum.servoy.com/u/tgs)\
**Post date:** [January 11, 2012, 9:03am UTC](https://forum.servoy.com/t/calculation-execution-and-relation-performance/15322/1 "2012-01-11T09:03:59Z")

</div>

I’m analysing the performance of a solution and figure out that a simple calculation takes an total execution time of 5 seconds (!) while showing a form.  
The calculation “cal\_result\_x” is on the table “order” and looks like

```auto
return quantity_x - order_to_order_items.sum_quantity_x

```

**My question is why does Servoy execute the calculation 10 times on showing the form and not only one time?**  
Because of the relation in the calculation the average execution time is 500 ms. I think this is high enough but 10 times of 500 ms is 5 seconds!

I have replaced the calculation by a method. The execution of the function takes 200 ms and will be executed only one time. This is really a significant advantage!

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [January 11, 2012, 1:13pm UTC](https://forum.servoy.com/t/calculation-execution-and-relation-performance/15322/2 "2012-01-11T13:13:04Z")

</div>

which servoy version are we talking about here  
What kidn of form do you show? recordview? tableview?

---

<div class="post-metadata">

**Author:** ![tgs](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@tgs](https://forum.servoy.com/u/tgs)\
**Post date:** [January 11, 2012, 1:18pm UTC](https://forum.servoy.com/t/calculation-execution-and-relation-performance/15322/3 "2012-01-11T13:18:52Z")

</div>

Hi Johan,

I’m on Servoy 6.0.4 and the form is in recordview.

Sorry for the missing info.

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [January 11, 2012, 2:17pm UTC](https://forum.servoy.com/t/calculation-execution-and-relation-performance/15322/4 "2012-01-11T14:17:26Z")

</div>

then i have no idea why that is triggered 10 times for you, it should only do it once,  
Somehow it does find that the input is constantly changing and is i guess flagging the calc to be executed again  
(if it really calculates for the same record and not for 10 different records)

Maybe you should try to create a case with that as a sample

---

<div class="post-metadata">

**Author:** ![tgs](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@tgs](https://forum.servoy.com/u/tgs)\
**Post date:** [January 12, 2012, 3:24pm UTC](https://forum.servoy.com/t/calculation-execution-and-relation-performance/15322/5 "2012-01-12T15:24:22Z")

</div>

I also have dedected the issue when running only this two codelines as onAction for a button:

```auto
databaseManager.hasRecords(auftrag_to_tp_auftrag__uid_auftrag);
application.output('true');

```

This is what I get on the servoy-admin Performance Statistics (I have cleared the statistics before!):  
  
As I understand is the Relation and the Aggregate SQL executed 10 times by fireing the function only once!?  
I’m wondering why?

Server Information  
Servoy version 6.0.4 -build 1227  
JVM Information  
java.vm.name=Java HotSpot™ Client VM  
java.version=1.6.0\_29  
PostgreSQL 9.1.2

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [January 12, 2012, 4:09pm UTC](https://forum.servoy.com/t/calculation-execution-and-relation-performance/15322/6 "2012-01-12T16:09:54Z")

</div>

thats just our special combined query to get also the data for the sibling records so that the next time if you would go to the next record nothing has to be get from the database anymore, we do max 10 at once

So that doesn’t mean that the calculation is executed 10 times, if you add an application output to the calc itself, is it really executed 10 times for exactly the same record (if you print the pk of that record)
