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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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.
Method 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0