嵌套函数或方法调用会降低应用程序的性能 [英] can nested function or method call reduce performance of application

查看:304
本文介绍了嵌套函数或方法调用会降低应用程序的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net和C#开发应用程序,其中我们的项目体系结构具有许多嵌套的函数调用.

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?

推荐答案

在Java中

几乎没有直接效果.内联35到325字节字节代码的简单方法,因此不会影响性能.几乎立即内联了35个字节的小型方法,默认情况下内联了频繁"的最多325个字节的称为方法"(可以增加).

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).

您遇到问题的地方是是否难于推理更多的代码.难以推理的代码使开发人员难以优化(在某些情况下甚至是JIT),例如假设您计算了一个昂贵的参数,该参数被嵌套的,嵌套的,嵌套的调用方丢弃.另一个常见的性能问题是转换,例如将String解析为一个double,然后将double转换为String,BigDecimal,最后再转换为String.如果没有很多嵌套级别,那么以字符串开头的内容可能会保留为字符串会更加明显.

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.

这篇关于嵌套函数或方法调用会降低应用程序的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆