jrubyfx icon indicating copy to clipboard operation
jrubyfx copied to clipboard

Make it faster by pre-compiling class injections

Open byteit101 opened this issue 12 years ago • 9 comments

reflection is slow, so if we pre-compile all of it, startup time will be faster (tested with old version reveal startup times goes from 15 seconds to 6 second)

byteit101 avatar Apr 13 '13 17:04 byteit101

Patrick, precompile what?

enebo avatar Apr 15 '13 14:04 enebo

the injections: https://github.com/jruby/jrubyfx/blob/master/lib/jrubyfx/dsl.rb#L183

If "compile" them down to a file that looks like

def Java::whatnot
  def setColor(x)
     # code
  end
end

this is much faster to load than reflecting over evrything again and class << self; define_method'ing

byteit101 avatar Apr 15 '13 15:04 byteit101

ahhh I see yeah we are not using Java reflection per se but we are using JI reflective methods to create those converters. When you first said this I thought you meant using jrubyc to make .class files. That is virtually never faster than loading a .rb. What you suggest would definitely be faster. It might be nice for us to make a declarative file describing all these conversions and then have a rake task to generate them. Then we can regenerate if we end up changing some stuff more easily?

enebo avatar Apr 15 '13 15:04 enebo

yea, that was my idea. We have two parts:

  1. stuff similar to what we have now, except it ouptuts ruby code
  2. declarative file to let us fix stuff on indivdual basis

and this is possible since the javafx api is fairly stable and does not change run to run

I've wanted to do the second for a while, but never got around to it. But now that we have the ruby FxmlLoader (btw, the ruby version is FxmlLoader, java is FXMLLoader to easily distinguish), its even slower than before, so I'm usually waiting 20 or so seconds for my awesome shiny app to show up. Also FxmlLoader does not use JRubyFX stuff, so it might be possible to load in parallel. I should also get rid of the 1MB of debug spew to make it faster :D. Random aside: whenever I get around to testing it, I can add ruby script support to FXML files (not just javascript anymore)

byteit101 avatar Apr 15 '13 15:04 byteit101

It seems like anything which is wrapping an existing method in FX should be in the declarative space and generated and individual helper additions to a FX builtin class should be in their own place probably laid out like they are now. Startup is somewhat dependent on # of parsed files so we might need to play with reducing files as an experiment, but I prefer to hack away on things like you noticed in this issue (JI reflection is a time sink) before getting down to that level of optimization. Especially lazy setup of FX classes since most FX classes are not used in most FX apps.

enebo avatar Apr 15 '13 15:04 enebo

WIP can be found at https://bitbucket.org/byteit101/jrubyfx but needs to be transformed into rakefile.

byteit101 avatar May 02 '13 22:05 byteit101

I have a mostly working version with rakefile (rake reflect, automatically called on gem and install also) pushed to master, but it appears I have broken some things. Namely, group {whaever} is always empty. I traced this down to overzealous enum overrides.It appears that opening a class wipes out java class heirarcy overloads and as such, if we overload the enums in Group, we must overload EVERYTHING!

Needless to say the fix is easy conceptually: don't override subclasses with the same methods or do override everything all the time.

byteit101 avatar May 07 '13 02:05 byteit101

Ok, that is solved and it cut down the size of the generated files quite a bit.

Still left to do:

  • Imports (java_import's)
  • DSL mappings

byteit101 avatar May 07 '13 03:05 byteit101

Imports and DSL mappings are done, just would like to add a few more things like color and maps. notes on what is still not in the procompiling:

borderPane: alias left right top bottom center method_missing (node_method_missing)

ColumnConstraints: new converter with a map (non-enum)

DragEvent: enum converter!!! alias accept transfer modes

Duration/Numeric: 5.ms methods

Drop Shadow.: color converter, new with color and enum

FileChooser: code

imageView: rectangle2d converter

labeled: color!

MediaPlayer: map converter (int + special)

ObservableValue: add_change_listener: TODO: investigate

Pagination: map (int + indeterminate special value)

Path: More complex m_m

ProgressIndicator/Bar: map converter + int

Gradients: enum in new

Region: map converter (int + special) insets converter

Rotate: map converter

Scene: color converter

Stage: code

Stop: color!

TableView: map!

Timeline: code map

Transition: animation convertsr

TreeView: some code

XYChart: adding stuff

byteit101 avatar Jun 12 '13 18:06 byteit101