[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Using Dynamic Proxies?



On Fri, 27 Jul 2001, ntran@InPhact.com wrote:
> I put together a simple comparison test between regular invocation and
> invocation using dynamic proxies (test code below). The proxies ranged from
> 0x - 4x slower than regular invocation. The cost of proxies will come in
> when the handler does significant work. Would it be possible to support both
> post processed proxies for the speed needy and dynamic proxies for the lazy?
> ;)

Yes, I think so. But laziness of the user is not the real problem. It should be
possible to have the generated proxies generated dynamicly/on-demand and
behave exactly like dynamic proxies, if this would be really desired. With the
exception that generating a generated proxies takes much more time under some
circumstances (generating the sources plus compiling). It's more a problem of
the laziness of us, the ozone developers ;) Having this explicit OPP call is
much easier to implement than dynamic generation and dynamic proxies are already
there and work out-of-the-box.

Anyway, I believe that using dynamic proxies inside ozone should be not that
difficult to implement. And once it is there we will easily find the better
(faster, easier to use, etc.) solution. We just need someone who finally tackle
this one ;)


Falko

> 
> Thanks,
> Scott
> 
> -----Original Message-----
> From: David Li [mailto:david@digitalsesame.com]
> Sent: Friday, July 27, 2001 3:34 AM
> To: ozone-dev@ozone-db.org
> Subject: Re: Using Dynamic Proxies?
> 
> 
> Falko Braeutigam wrote:
> 
> > On Wed, 25 Jul 2001, you wrote:
> > 
> >>I was wondering if/when ozone was moving to dynamic proxies? 
> >>
> > 
> > AFAIK nobody is working on this. We don't even have the benchmark numbers
> that
> > compare dynamic against generated proxies, as we discussed it earlier.
> Shouldn't
> > be a real problem but unfortunately nobody is willing/able/whatever to
> actually
> > tackle this one. Would you like to help us out here?
> > 
> 
> 
> No solid number yet but I think this can be taken as a reference number.
> 
> For a null method call, DynamicProxy call is about 5 times slower than a 
>   non final method call.
> 
> I haven't gotten arround to finish up the dynamic proxy benchmark. Will 
> try again this weekend.
> 
> David Li
> DigitalSesame
> 
> 
> ---Test Code---
> 
> import java.lang.reflect.*;
> 
> public class DynamicTest {
>     
>     public static void main(String[] args) {
>         DynamicTest test = new DynamicTest();
>         echo("First run");
>         test.runRegular(50);
>         test.runDynamic(50);
>         echo("Second run");
>         test.runRegular(100);
>         test.runDynamic(100);             
>         echo("Third Run");
>         test.runRegular(1000);
>         test.runDynamic(1000);   
>         echo("Tests done!");
>         
>     }
>     
>     public void runRegular(int iterations) {
>         long startTime = System.currentTimeMillis();
>         echo("Regular - " + startTime);        
>         Fi regular = new Fi();
>         String in = "in";
>         for (int i=0; i<iterations; i++) {
>             ((Fo)regular).outSomething();
>             ((Fum)regular).inSomething(in);            
>         }
>         echo("Regular invocation with " + iterations + " iterations took " 
>             + (System.currentTimeMillis() - startTime) + "ms");
>     }
>     
>     public void runDynamic(int iterations) {
>         long startTime = System.currentTimeMillis();
>         echo("Dynamic - " + startTime);
>         Proxy dynamic = (Proxy) Fee.newInstance(new Fi());
>         String in = "in";
>         for (int i=0; i<iterations; i++) {
>             ((Fo)dynamic).outSomething();
>             ((Fum)dynamic).inSomething(in);            
>         }
>         echo("Dynamic invocation with " + iterations + " iterations took " 
>             + (System.currentTimeMillis() - startTime) + "ms");    }
>     
>     public static void echo(Object obj) {
>         System.out.println(obj);
>     }
> }
> 
> class Fee implements InvocationHandler {
>     private Object obj;
>     
>     private Fee(Object obj) {
>         this.obj = obj;
>     }
>     
>     public static Object newInstance(Object obj) {
>         return Proxy.newProxyInstance(
>             obj.getClass().getClassLoader(),
>             obj.getClass().getInterfaces(),
>             new Fee(obj));
>     }
>     
>     public Object invoke(Object proxy, Method m, Object[] args) throws
> Throwable {
>         try {
>             return m.invoke(obj, args);
>         } catch (Exception e) {
>         }
>         return null;
>     }
> }
> 
> class Fi implements Fo, Fum {
>     private String something = "something";
>     public String outSomething() {
>         return something;
>     }
>     
>     public void inSomething(String s) {
>         something = s;
>     }
>     
> }
> 
> interface Fo {
>     public String outSomething();
> }
> 
> interface Fum {
>     public void inSomething(String s);
> }
> ----------------------------------------------------------------------
> Post a message:         mailto:ozone-dev@ozone-db.org
> Unsubscribe:            mailto:ozone-dev-request@ozone-db.org?body=unsubscribe
> Contact adminstrator:   mailto:ozone-dev-owner@ozone-db.org
> Read archived messages: http://www.ozone-db.org/
> ----------------------------------------------------------------------
-- 
______________________________________________________________________
Falko Braeutigam                              mailto:falko@smb-tec.com
SMB GmbH                                        http://www.smb-tec.com

----------------------------------------------------------------------
Post a message:         mailto:ozone-dev@ozone-db.org
Unsubscribe:            mailto:ozone-dev-request@ozone-db.org?body=unsubscribe
Contact adminstrator:   mailto:ozone-dev-owner@ozone-db.org
Read archived messages: http://www.ozone-db.org/
----------------------------------------------------------------------