cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Giacomo Pati <giac...@apache.org>
Subject Re: cvs commit: xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/impl SlideSource.java
Date Thu, 09 Jan 2003 16:38:46 GMT
On Thu, 9 Jan 2003, Stephan Michels wrote:

>
>
> On Thu, 9 Jan 2003, Giacomo Pati wrote:
>
> > On Thu, 9 Jan 2003, Stephan Michels wrote:
> >
> > >
> > >
> > >
> > > On 9 Jan 2003 giacomo@apache.org wrote:
> > >
> > > > giacomo     2003/01/09 06:35:25
> > > >
> > > >   Modified:    src/scratchpad/src/org/apache/cocoon/components/source/impl
> > > >                         SlideSource.java
> > > >   Log:
> > > >   make some method package protected instead of privat to increase performance
by avoiding 'access emulated by a synthetic accessor method' (objected by eclipse)
> > > >
> > >
> > >
> > > Hmm, do really think that using package protected modifiers instead of
> > > private modifiers make the implementation faster. For some time I read
> > > an article, which says the private modifier make the fastest access
> > > possible.
> >
> > You can prove that by yourself using the following code:
> >
> > public class A
> > {
> >   private int a;
> >
> >   public A()
> >   {
> >     AA aa = new AA();
> >   }
> >
> >   private int foo( AA a )
> >   {
> >     AA b = a;
> >     return 0;
> >   }
> >
> >   public class AA
> >   {
> >     public AA()
> >     {
> >       int b = a;
> >     }
> >     public void b()
> >     {
> >       foo( this );
> >     }
> >   }
> > }
> >
> > Compile this and produce an assembly listing (javap -c A).
> >
> > Now, remove the private modifier from the 'int a' as well as from method
> > foo to make it package protected.
> >
> > If you compare these assably listing you'll see what java does with it.
> >
> > Access to the private variable 'a' as well as to the private method
> > 'foo' from within the inner class is indirected by use of
> > a synthetic accessor method.
>
> Okay, now I see what you mean, because of the inner class
> SlideSourceOutputStream the accessor methods will be produced. And
> now Eclipse thinks that if I change all used member variables to
> package private all run faster.
>
> If you insert
>
>   private int bar()
>   {
>     return a+3;
>   }
>
> you will see that bar doesn't need a synthetic accessor method.

Of course not, it's in the same instance.

> So have a bit more Performance, with a package private member variables.
>
> First rule of performance tuning: Don't do it. cit. Bitter Java(I think)

or better 'don't access private outer class methods/variables from inner
classes'.

Ok, does any other here have an oppinion on this?

Giacomo


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message