Accessor Method Performance and Optimization

前端 未结 6 2397
有刺的猬
有刺的猬 2021-02-15 12:11

Often, I come across code where the Getter method is repeatedly used/abused to get some value or pass it as a method parameter, for ex:

public c         


        
6条回答
  •  深忆病人
    2021-02-15 12:51

    I did some research on this topic, after asking the question and found what I was looking for. The problem was that I didn't use the right terminology, when framing the question. 'Inline Expansion' (Compiler Inlining) is what I was looking for. Here's a quote from Wiki:

    In computing, inline expansion, or inlining, is a manual or compiler optimization that replaces a function call site with the body of the callee. This optimization may improve time and space usage at runtime, at the possible cost of increasing the final size of the program (i.e. the binary file size).

    I also found that this topic has already been discussed on this site:

    1) Do getters and setters impact performance in C++/D/Java?

    Here's a quote from the above link:

    In Java, the JIT compiler will probably inline it sooner or later. As far as I know, the JVM JIT compiler only optimizes heavily used code, so you could see the function call overhead initially, until the getter/setter has been called sufficiently often.

    2) Inlining In Java

提交回复
热议问题