[gui-dev] Re: [codepatch] A small optimization for SchemaReplyCollectionMapper

Roger Kapsi <[email protected]> Fri, 23 Jul 2004 20:01:49 +0200
Newsgroups gmane.network.gnutella.limewire.gui.devel
Message-ID <[email protected]>
Hi Philippe,

I'm maybe missing something but how does this has an impact on the  
launch time or memory usage? In both cases the static class variable is  
being initialized if SchemaReplyCollectionMapper is touched the first  
time and never if no one touches it.

  Roger


public class ClassA {
     private static ClassA instance = new ClassA();

     public static ClassA instance() {
         System.out.println("ClassA.instance()");
         return instance;
     }

     private ClassA() {
         System.out.println("Constructor ClassA");
     }
}

public class ClassB {
     public static void main(String[] args) throws Exception {
         System.out.println("ClassB.main()");
         ClassA clazz = null;
         System.out.println("Touch ClassA in 5 seconds...");
         Thread.sleep(5000);
         clazz = ClassA.instance();
     }
}

On Jul 23, 2004, at 6:12 PM, Philippe Verdy wrote:

> There's a tradeoff here between using lazy initialization (requiring
> synchronized instanciation) which boost aplication startup, and a very  
> tiny
> price related to synchronization of a method which is not so frequently
> called: mapping schema replies occurs only when a user is receiving  
> replies
> to his own searches, and at most it would occur about 200 to 400 times  
> per
> search initiated by the user, and only provided that all results have
> embedded meta-data.
>
> In practice, a search will run for a couple of minutes and will return  
> about
> 80-100 results with meta-data, so this accessor will be used on average
> about 1-2 times per second. This is small enough to keep the
> synchronizartion on this, with the benefit of shortening the  
> application
> launch time.
>
> Remember that there are still tons of users running a PC with less than
> 128MB RAM, and not all running Windows XP on a fast processor > 1GHz:  
> on
> these system the application launch time, including the JVM startup  
> and the
> VM swap on disk, is quite long, and I have a 4-years old PC for which
> LimeWire requires about 150 seconds to start and again 2 minutes to get
> connected. This very notable for most notebook users (unless you use  
> one of
> the new very fast notebooks which now outperform many desktops).
>
> ----- Original Message -----
> From: "Roger Kapsi" <[email protected]>
> To: <[email protected]>
> Sent: Friday, July 23, 2004 12:30 AM
> Subject: [codepatch] A small optimization for  
> SchemaReplyCollectionMapper
>
>
>>
>> While tracking a NPE in DAAP I saw that SRCMapper.instance() is
>> unnecessarily synchronized. This patch will surely save some
>> nanoseconds! :)
>>
>> cu
>>   Roger
>>
>>
>
>
> ----------------------------------------------------------------------- 
> -----
> ----
>
>
>> _______________________________________________
>> codepatch mailing list
>> [email protected]
>> http://www.limewire.org/mailman/listinfo/codepatch
>>
>

_______________________________________________
gui-dev mailing list
[email protected]
http://www.limewire.org/mailman/listinfo/gui-dev