Usually reading fields in different objects even through methods does not make any difference. As soon as your load goes up on a specific 'hot spot' the Java hotspot compiler optimizes the bytecode on-the-fly so that it won't make a difference anymore.
That is one of the reasons why the JVM is so blazing fast. And it is one of the reasons why people tell you the following:
- do not micro-optimize Java code for performance, because you are assuming something. Try to find evidence, first
- especially avoid the most simple things like inlining methods. Hotspot does all of that already
- the simpler and cleaner your code the more the Java hotspot compiler can do for you regarding performance
If you notice performance issues, always check for memory issues first. Aside from bugs in algorithms that increase runtime complexity...
The most common reasons for performance issues (check for them first):
- Running out of heap space (and related: garbage collection forever, high cpu load). You can check that with tools like
visualvm and its plugins.
- Contention: Concurrency issues with threads battling for the same resources. If you do not have I/O waits and idle cpus this is likely your problem. Use tools like
top to check that.
- Enough memory configured, but your system does a lot of I/O, either because of swapping (too few physical memory) or because of your software waiting for I/O. Check for I/O waits
Especially if you do have a lot of data, variables, particles as you say, check first for the obvious things :-)
Good luck!
getmethods or are the variables declaredpublic?