On 8/17/07, Charles Oliver Nutter <[EMAIL PROTECTED]> wrote:
>
> Kenneth McDonald wrote:
>
> > A related question on the efficiency front. Let's say that, purely for
> > my Ruby code, I define a new subclass of JButton, 'class MyButton <
> > javax.swing.JButton; . . .; end'. Now, I can use those new features
> > happily in JRuby, and Java will still happily treat it as a button,
> > _but_, how much of a performance hit does pure Java code take when
> > accessing and manipulating that object, since it isn't manipulating a
> > 'normal' Java object. (I'm not looking for exact numbers here, 'big'
> > indicating that method calls/field accesses take a lot longer, or
> > 'small' indicating that don't take too much longer, would be fine :-) )
> > This is something I'd like to know in general, and also it can
> > potentially be quite important in complex dynamic Swing layouts, where
> > speed is of the essence...
> >
> > And, if the answer is 'big', an ideas on how much compilation might do
> > to improve this?
>
> I think it's not "big" enough to be noticed much in a large swing
> application. Yes, the subclass's logic will be visible to Java. Yes,
> using that subclass will bring along some invocation/execution overhead
> due to our dynamic dispatch plumbing. But we don't have a good number to
> express how much that overhead is.


It should also be noted that any performance hit applies only to Java
methods you override in your subclass (the body of which are implemented in
Ruby); for pure Java-Java method calls / field accesses, there's no
performance hit at all. Consider the following:

  class RedButton < javax.swing.JButton
    Red = java.awt.Color::RED
    def paintComponent(graphics)
      graphics.color = Red
      graphics.fill_rect 0,0,20,20
    end
  end

  aFrame.add RedButton.new

Calls to paintComponent will certainly be slower than if it were implemented
in Java, and the calls to the Graphics object and JFrame#add will also incur
some overhead (though not a lot).  But there's no performance penalty for
any other calls that the JFrame (or a layout manager, or other component)
might make on other methods of JButton/AbstractButton/JComponent/etc.
That's still straight Java.

-Bill

Reply via email to