Include_class performance

Since I’m still struggling with the startup performance of my
JRuby/Swing application I would like to know if it would make sense not
to use include_class. The following test prog spends most of it’s time
with the include_class statements. In my real programm all those
include_class statements contribute about 1.5 seconds to the startup
time. Because of that I’m thinking about removing all those
include_class statements and use the complete package name when creating
an object. Good or bad idea ?

Regards
Roger

require “java”

t1 = Time.new

include_class “javax.swing.JTable”
include_class “javax.swing.JLabel”
include_class “javax.swing.JButton”

puts (Time.now - t1) * 1000

1.upto 1000 do
x = Java::JavaxSwingJTable.new
y = Java::JavaxSwingJLabel.new
b = Java::JavaxSwingJButton.new
end

puts (Time.now - t1) * 1000


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I suspect your times won’t change. Both forms of including Java
classes needs to stand up the Ruby methods for all the same-named
methods for the Java classes you are using and Swing is pretty
gigantic. I expect this set up is where the time is going. Perhaps
use --client to speed things up?

-Tom

On Fri, Jun 4, 2010 at 1:46 AM, Roger G. [email protected] wrote:

1.upto 1000 do

http://xircles.codehaus.org/manage_email


blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I suspect your times won’t change. Both forms of including Java
classes needs to stand up the Ruby methods for all the same-named
methods for the Java classes you are using and Swing is pretty


But I’m seeing here a different behaviour. Or is there a flaw in my
benchmarks ?

Regards
Roger

1.) Skript

require “java”

t1 = Time.now

1.upto 1000 do
x = Java::JavaxSwingJTable.new
y = Java::JavaxSwingJLabel.new
b = Java::JavaxSwingJButton.new
a = x.getClass().name
end

puts (Time.now - t1) * 1000

=> needs 30ms

2.) Skript

require “java”

t1 = Time.now

include_class “javax.swing.JTable”
include_class “javax.swing.JLabel”
include_class “javax.swing.JButton”

1.upto 1000 do
x = JTable.new
y = JLabel.new
b = JButton.new
a = x.getClass().name
end

puts (Time.now - t1) * 1000

=> needs 1000ms

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Now that is peculiar. Can you put these benchmarks in a bug? Perhaps
there’s something obviously wrong.

If you can, give it a try in JRuby 1.4.1 as well, to see if the
numbers are different.

On Fri, Jun 4, 2010 at 12:32 PM, Roger G. [email protected] wrote:

1.) Skript
end
t1 = Time.now
end


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Oh wait, I just realized something…

âž” jruby -rjava -e “p Java::JavaxSwingJTable.new; p
javax.swing.JTable.new”
Java::JavaxSwingJtableNew
#Java::JavaxSwing::JTable:0x18b9a72

If you add a :: before JTable, as in Java::JavaxSwing::JTable, you’ll
see roughly the same amount of time.

It’s also worth pointing out that Swing in particular starts up the
whole windowing subsystem when it first loads a class, so you may want
to compare how long it takes to include the first Swing class versus
including additional classes. In general, including even a large class
with many dependencies is pretty fast.

  • Charlie

On Sat, Jun 5, 2010 at 12:16 PM, Charles Oliver N.
[email protected] wrote:

methods for the Java classes you are using and Swing is pretty
t1 = Time.now
=> needs 30ms
include_class “javax.swing.JButton”
=> needs 1000ms


To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Thanks for the clarification. My mistake. Seems I have to live with the
slow startup.

Regards
Roger

Am 05.06.2010 um 19:49 schrieb Charles Oliver N.:

whole windowing subsystem when it first loads a class, so you may want

x = Java::JavaxSwingJTable.new
2.) Skript
x = JTable.new


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

We do want to improve startup, if possible…


And your efforts are highly appreciated.

Do make sure that you’re running the client VM (jruby -v should show
“client” somewhere). If you’re not, you may need to pass --client
and/or -J-d32 to JRuby to put the JVM in client mode (or set
JAVA_OPTS="-d32 -client").


Already use that and it seems that this is the only way to improve
startup time right now.

Regards
Roger


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

We do want to improve startup, if possible…but sometimes it’s just
costs intrinsic to running on the JVM.

Do make sure that you’re running the client VM (jruby -v should show
“client” somewhere). If you’re not, you may need to pass --client
and/or -J-d32 to JRuby to put the JVM in client mode (or set
JAVA_OPTS=“-d32 -client”).

On Sat, Jun 5, 2010 at 1:22 PM, Roger G. [email protected] wrote:

âž” jruby -rjava -e “p Java::JavaxSwingJTable.new; p javax.swing.JTable.new”
with many dependencies is pretty fast.

  a = x.getClass().name

  a = x.getClass().name


To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Sat, Jun 5, 2010 at 2:40 PM, Roger G. [email protected] wrote:

JAVA_OPTS=“-d32 -client”).
http://xircles.codehaus.org/manage_email

Hi - here are the test cases for Jruby 1.4 (under CentOS 5 running a
on netbook.)

Case 1:

require ‘java’

t1 = Time.new

1.upto 1000 do
x=Java::JTable.new
y=Java::JLabel.new
b=Java::JButton.new
a=Java::Class.new
end

puts (Time.now - t1) * 1000

TIME=124

Case 2:

require ‘java’

t1 = Time.new

1.upto 1000 do
x = Java::javax.swing.JTable.new
y = Java::javax.swing.JLabel.new
b = Java::javax.swing.JButton.new
a = x.getClass().name
end

puts (Time.now - t1) * 1000

TIME=3163


Enjoy global warming while it lasts.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email