Forum: JRuby is this a good idea to increase performance?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Phil S. (Guest)
on 2009-03-10 21:11
(Received via mailing list)
Charles, I know you have been working on Duby so you don't keep having
to write Java code for JRuby.  Theory is that static type perf is much
faster than for dynamic types.

I had a thought pop in my head.  Would it be possible to somehow
annotate a method signature in Ruby code to allow the JVM to use
static typing?  So instead of dropping to Java for performance
sensitive code, you could annotate the method and write the code in
Ruby.

So for

def blah(input1, input2, input3)

you could write

#jruby:type (String, String, Fixnum)
def blah(input1, input2, input3)

For regular ruby execution the annotation (which is just a comment)
would be ignored, but JRuby could use the info to optimize.

I have no idea what the implications are for this of course....

phil

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Charles Oliver N. (Guest)
on 2009-03-10 22:09
(Received via mailing list)
phil swenson wrote:
> Charles, I know you have been working on Duby so you don't keep having
> to write Java code for JRuby.  Theory is that static type perf is much
> faster than for dynamic types.
>
> I had a thought pop in my head.  Would it be possible to somehow
> annotate a method signature in Ruby code to allow the JVM to use
> static typing?  So instead of dropping to Java for performance
> sensitive code, you could annotate the method and write the code in
> Ruby.

The idea has certainly crossed my mind, and I've even prototyped it. It
would definitely make a big difference compared to what we have now.
Basically what it would do is a single type check at the top of the
method, and subsequent calls would dispatch straight to that type. This
would immediately improve performance for core classes (since it would
dispatch straight to RubyFixnum#op_plus, for example) and could be
expanded to improve performance against other Ruby types (by just
dispatching directly to them without additional type checks).

It would also be useful as a simple type verification too.

I'm hoping that at some point we can move more of the compiler/optimizer
logic into Ruby so folks like you can play with it. But discussing
syntax etc right now would help move things along until that happens :)

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
This topic is locked and can not be replied to.