harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikhail Loenko" <mloe...@gmail.com>
Subject [classlib] performance tips
Date Fri, 10 Mar 2006 07:58:07 GMT
Hello

May be it is obvious and everybody knows it from babyhood, but anyway...

Everybody knows that this two examples of code do the same:
class test {
    public Object field = null;
}

and

class test {
    public Object field;
}

But if you disassemble these two classes, you'll see that the first example
has a 6 instruction constructor:

   0: aload_0
   1: invokespecial #1; //Method java/lang/Object."<init>":()V
   4: aload_0
   5: aconst_null
   6: putfield #2; //Field field:Ljava/lang/Object;
   9: return

while the second one has only 3 of them:
   0: aload_0
   1: invokespecial #1; //Method java/lang/Object."<init>":()V
   4: return

So having explicit assignments of default values slows down constructor.

Thanks,
Mikhail

Mime
View raw message