Reading this question and this answer I know that accessing fields will cost some performance in AOT compilers (thanks to JVM I can forget about it)
Now please guide me about this scenario:
public class Foo
{
Object fooObject;
}
public class Bar
{
Foo foo;
Object fooObjectCopy = foo.fooObject; // fooObject replica of object foo (not a clone)
void barMethod1()
{
doSomething (fooObjectCopy);
}
void barMethod2()
{
doSomething (foo.fooObject);
}
}
Both barMethod1()
and barMethod2()
do the same thing. The question is which one does better (in terms of performance) if:
fooObject
is a primitive typefooObject
is an object instance
P.S. Please consider both accessing cost and cache miss.