1.

How Do You Optimize Methods In A Class?

Answer»

• Avoid creating temporary objects WITHIN frequently called methods.
• Define methods that accept reusable objects to be filled in with data, rather than methods that return objects holding that data.
• Use methods that alter objects without MAKING copies.
• Eliminate repeatedly called methods where alternatives are possible [For example, if you are processing a vector in a loop, get the size of the vector in the BEGINNING in a length local variable rather than calling size() method on the vector in the condition part of the for loop]
• Use private and STATIC methods and final classes to encourage inlining by the compiler.
• Inline methods manually where it is appropriate • KEEP methods short and simple to make them automatic inlining candidates.
• Access to private member by the inner classes to the enclosing class goes by a method call even if it is not intended to.
• Keep synchronized methods out of loops if you possibly can.

• Avoid creating temporary objects within frequently called methods.
• Define methods that accept reusable objects to be filled in with data, rather than methods that return objects holding that data.
• Use methods that alter objects without making copies.
• Eliminate repeatedly called methods where alternatives are possible [For example, if you are processing a vector in a loop, get the size of the vector in the beginning in a length local variable rather than calling size() method on the vector in the condition part of the for loop]
• Use private and static methods and final classes to encourage inlining by the compiler.
• Inline methods manually where it is appropriate • Keep methods short and simple to make them automatic inlining candidates.
• Access to private member by the inner classes to the enclosing class goes by a method call even if it is not intended to.
• Keep synchronized methods out of loops if you possibly can.



Discussion

No Comment Found