can nested function or method call reduce performance of application

爱⌒轻易说出口 提交于 2019-12-25 04:45:25

问题


I am developing application using asp.net and C# in which our project architecture has lot of nested function calls.

public Employe GetEmployeOrder(orderid, employe){
      GetEmployeOrderWithDetails(orderid, employe.ShippingId,BillingId);
 }

public Employe GetEmployeOrderWithDetails(guid orderid,guid ShippingId,guid BillingId)
{
  //  Another function call
}

You might have got an idea what scenario I am talking about. If I have such nested calls then is it going to affect performance of my application?


回答1:


In Java

There is little direct effect. Simple methods of between 35 and 325 bytes of byte code get inlined so they don't impact performance. Small methods of 35 bytes are inlined almost immediately and "frequently" called method of up to 325 bytes are inlined by default (This can be increased).

Where you run into problems is if more code is harder to reason about. Code which is harder to reason about, is hard for the developer to optimise (and the JIT in some cases) e.g. say you compute an expensive argument which the nested, nested, nested caller discards. Another common performance problem is transformations e.g. a String is parsed into a double which is converted into a String, into a BigDecimal and finally a String again. If you didn't have some many levels of nested it would be more obvious that what starts as a String could stay a String.

As is usually the case, if in doubt assume the simplest, clearest code is best.




回答2:


Simply - yes

You should keep your code as straight as possible, each nested function call is creating load on program memory stack - processor is remembering where to jump back, and what to bring back, also not finished functions are remembered on stack.

Simpler? - recurrence loop over and over may lead to funny things, but still, less than 20 levels or recurrences are almost invisible.



来源:https://stackoverflow.com/questions/27875136/can-nested-function-or-method-call-reduce-performance-of-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!