fast access to fields and final methods
Tim Panton-Westpoint Ltd
tpanton at attglobal.net
Sat Nov 12 19:29:10 PST 2005
"Greg Munt" <greg at lateral-ltd.com> wrote:
__________
>If performance is that much of an issue, it makes me wonder why you are
>implementing your software in Java at all..
>
>-----Original Message-----
>From: Caro, Samuel <Samuel.Caro at USAHQ.UnitedSpaceAlliance.com>
>To: advanced-java at xcf.berkeley.edu <advanced-java at xcf.berkeley.edu>
>Date: Monday, February 12, 2001 05:35
>Subject: fast access to fields and final methods
>
>
>>
>>
>>Has anyone done some performance tests
>>comparing classes with public fields vs. classes with final methods
>>
>>for example
>>
>>// This is what we may HAVE to do
>>public class A{
>> public Object value;
>>}
>>
>>// This is what we are considering but we won't be able to override
>>// the methods
>>public class B{
>> private Object value;
>> public final void setValue(Object newValue){
>> value = newValue;
>> }
>> public final Object getValue(){
>> return value;
>> }
>>}
>>
>>// This is what I really want because I think it is a better design
>>// But it is not fast enough for our purposes
>>public class
>
>> private Object value;
>> public void setValue(Object newValue){
>> value = newValue;
>> }
>> public Object getValue(){
>> return value;
>> }
>>}
>>
>>
>>We tried version C but it was not fast enough and we are looking for
>>performance
>>anywhere we can.
>>
>>We will have hundreds, maybe thousands, of Objects of this type
>>and we are going to be changing many of them every second
>>
>>My questions are,
>>From your experience is class B that much faster than C?
>>Is B closer to A than to C in performance?
>>
>>I really don't like the idea of exposing those fields by making them public
>>If I could somehow simulate the concept of friend classes it would be
>>perfect
>>Does anyone know a trick to have "friend-like" classes?
>>My "friend-like" classes WILL NOT be in the same package so package level
>>access is not an option
I think that the speed difference
you are seeing is a result of the
inlining strategy of the compiler/jit
you are using. You should try different jvms and/or compilers.
In this case I'd try sun's hotspot vm
with -server, which should inline
pretty aggressively. On intel
IBM's jvm is always worth a try.
(on jdk 1.1 we found the compiler
would only inline if you compiled
all relevant files in one shot:
javac -O a.java b.java c.java ,
but it made a huge difference in our
-admittedly different- case)
If that doesn't help, perhaps
you need to look at refactoring
the problem to reduce the
assignments. You might be able
to add an aggregate object layer, containing references to multiple
sibling objects and thus manipulate
them as a group.
HtH,
Timhttp://www.westpoint.ltd.uk/
Internet reconnaissance services.
---
To unsubscribe, mail advanced-java-unsubscribe at xcf.berkeley.edu
To get help, mail advanced-java-help at xcf.berkeley.edu
More information about the Advanced-java
mailing list