Why JRuby?
Who?




  Thomas      Charlie
@tom_enebo   @headius
What is JRuby?
JRuby is Ruby! *
   1.8.7 & 1.9.3 compatibility
   drop-in replacement

                         * see next slide
*caveats

• Weak but improving low-level UNIX stuff
• No C extension support
 • Not maintained...off by default in 1.7
• Some features differ or unavailable
 • ObjectSpace, trace funcs, callcc, fork...
JRuby is Ruby
     ...and then some?
Announcing JRuby 1.7.0

• Ruby 1.9.3 compat (--1.8 for 1.8.7)
• Java 7 invokedynamic support
• Much awesomeness over 1.6.x
Getting Started

1. Install a JVM
2. rvm install jruby
3. Profit!
        % jruby -e ‘puts “wowee”’
The JRuby Difference
JRuby Team

                  Charlie                       Tom




Nick   Hiro   Marcin        Nahi    Wayne      Subbu   Douglas   Douglas
                                                                  Douglas
                                                                  Contribs




                Douglas
                 Douglas       Douglas
                                Douglas     Douglas
                                              Other
                                             Douglas
                 OpenJDK         Android
                                               JVMs
JRuby

                JRuby
Yoko




          JVM
J. Rose



           OS (libc, ...)
MRI

nobu
           MRI




       OS (libc, ...)
JRuby

                JRuby
Yoko




          JVM
J. Rose



           OS (libc, ...)
We get it for Free!

               JVM
J. Rose



  Garbage                     Profiled
               Native JIT   Optimizations
 Collection

  Native        Tooling     Cross Platform
 Threading
Profile: John Rose
    • JVM Engineer since 1997
    • Invented C* Language
    • JSR 292 lead
JVM over time
(what if we were lazy?)
Go Java Go!                       300% for free
             JRuby 1.0.3 (bm_red_black_tree.rb)

 30



22.5



 15



 7.5



   0
  Java 1.4     Java 5                 Java 6             Java 7
Go Java Go!                          300% for free
             JRuby 1.0.3 (bm_red_black_tree.rb)                MRI 1.8

 30



22.5



 15



 7.5



   0
  Java 1.4               Java 5                   Java 6                 Java 7
JVM Benefits
Cross-Platform
JVM is everywhere

• Unix++, Windows
• Exotic platforms: zLinux, OpenVMS, AS/400
• Mobile: Android’s Dalvik, Embedded JVMs
Java bytecode ==
    portability
actionmailer-javamail, active_documentum, activerecord-jdbc-adapter, activerecord-jdbcdbf-adapter, activerecord-jdbcderby-adapter, activerecord-jdbch2-
adapter, activerecord-jdbchsqldb-adapter, activerecord-jdbcmssql-adapter, activerecord-jdbcmysql-adapter, activerecord-jdbcpostgresql-adapter, activerecord-
    jdbcsqlite3-adapter, activerecord-netezza-adapter, activerecord-vertica-adapter, akephalos, akephalos-nerian, akephalos2, akka-actor-jars, akka-remote-jars,
    akubra_llstore_migrate, Antwrap, async-http-client-jars, atomic, atoulme-Antwrap, autotest-java, bbrowning-deltacloud-client, bbrowning-deltacloud-core,
   bcrypt-ruby, bee_java, berkeley-db-java-jars, bert, bio-maf, blockenspiel, boc, bond, bosdk, bouncy-castle-java, boxed-geminabox, brute-fuzzy, bryanl-gherkin,
 bson, buby, buildr, buildr-resolver, buildrizpack, butternut, capistrano-java, capybara-java_script_lint, carrierwave-neo4j, carrierwave_imagevoodoo, cassandra-
   jars, chrest, cloby, commons-io-jars, concurrently, contextual, coupler, cucumber-java, cucumber-jvm, cuke4duke, cuuid, dm-ldap-adapter, dm-lucene-adapter,
  do-jdbc_sqlserver, do_derby, do_h2, do_hsqldb, do_jdbc, do_mysql, do_openedge, do_oracle, do_postgres, do_sqlite3, do_sqlserver, doubleshot, dripdrop,
    dubious, duby, engineyard-visualvm, epall-limelight, errbit_zmq_handler, eurydice, euston, euston-daemons, euston-eventstore, euston-projections, euston-
   rabbitmq, euston-websites, eventmachine, excemel, faye-websocket, ffi, fig, file-find, fishwife, foreman, forkit, forkjoin, gamelan, gemshit, geoip-jars, get_back,
 gherkin, glassfish, gravitext-util, gravitext-xmlprod, grizzly, guava-jars, hadoop-find, hashdot-test-daemon, hiredis, hitimes, hope, hostor, hot_bunnies, hourglass,
 hpricot, http_parser.rb, inline_javascript, iudex, iudex-async-httpclient, iudex-barc, iudex-brutefuzzy-protobuf, iudex-brutefuzzy-service, iudex-char-detector,
 iudex-core, iudex-da, iudex-filter, iudex-html, iudex-http, iudex-http-test, iudex-httpclient-3, iudex-jetty-httpclient, iudex-rome, iudex-simhash, iudex-worker,
            ivy-jars, iyyov, jactive_support, java-autotest, java-inline, java2ruby-xmldsig, java_bin, java_inline, java_override, java_properties, java_streamify,
java_testing_guff, javabean_xml, javaclass, javaeye4r, javagems, javajake, javaobj, javaobjs, javaobs, javaparse, javasand, javascript-securehash-rails, javascript-state-
                machine-rails, javascript_auto_include, javascript_eraser, javascript_features, javascript_i18n, javascript_localize, javascript_safe_logger,
  javascript_util_asset_pack, javascripto, javascripto-rails, jdbc-derby, jdbc-hsqldb, jdbc-jtds, jdbc-openedge, jdbc-openedge-internal, jdbc-postgres, jdbc-sqlite3,
      jedis-jars, jena-jruby, jessica, jettr, jetty, jetty-jsp, jgeoip, jms4r, jpdfer, jrack_handlers, jrtm, jruby-activemq, jruby-akka_jars, jruby-elasticsearch_jars, jruby-
      httpclient, jruby-launcher, jruby-management, jruby-metrics, jruby-pageant, jruby-vijava, jruby_gc_stats, jruby_sandbox, jruby_threach, jrubyconf-button,
  jsmetric4java, json, json-jruby, jsound, kb-activerecord-jdbc-adapter, kirk, kyotocabinet-java, ladle, latex-decode, launchy, libnotify, limelight, linecache, logback,
       logback-jars, looksee, lumix, mack-javascript, markdownj, maven_irb_plugin, metrics-core-jars, metrics-java, mguymon-buildr, mikka, mini_aether, mirah,
mirah_model, miso-java, mixology, mm_mq, mongrel, msgpack-idl-java, msgpack-jruby, multimeter, naether, nanoc-javascript-concatenator, neo4j, neo4j-admin,
      neo4j-advanced, neo4j-community, neo4j-core, neo4j-enterprise, neo4j-spatial, neo4j-will_paginate, neo4j-wrapper, netty-jars, ning-compress-jars, nio4r,
nokogiri, nokogiri-fitzsimmons, nokogiri-maven, nosqoop4u, ontomde-demo-java5, ontomde-java, ontomde-java-frontend, ontomde-uml2-java, ontomde-uml2-
               kbjava, open_nlp, pacer, pacer-dex, pacer-neo4j, pacer-orient, pelops-jars, persvr, pg_array_parser, protobuf-jars, pry, puma, qtjruby-core,
      qwirk_active_mq_adapter, qwirk_jms_adapter, rabbitmqadmin-cli, ragweed, rails_javascript_helpers, rakejava, rave, rcov, realityforge-jekyll, realityforge-
    jekylltask, redcar-bundles, redcar-clojure, redcar-filter-through-command, redcar-groovy, redcar-icons, redcar-javamateview, redcar-javascript, redcar-mirah,
        redcar-svnkit, redcar-xulrunner-win, RedCloth, refinerycms-javascripts, reigns, revo-nokogiri, rika, rjack-async-httpclient, rjack-commons-codec, rjack-
commons-dbcp, rjack-commons-dbutils, rjack-commons-pool, rjack-httpclient-3, rjack-httpclient-4, rjack-icu, rjack-jackson, rjack-jdom, rjack-jets3t, rjack-jetty,
     rjack-jetty-jsp, rjack-jms, rjack-jms-spec, rjack-logback, rjack-lucene, rjack-maven, rjack-mina, rjack-nekohtml, rjack-protobuf, rjack-qpid-client, rjack-rome,
  rjack-slf4j, rjack-solr, rjack-tarpit, rjack-xerces, rmagick4j, rmodbus, rtm-javatmapi, rtm-majortom, rtm-ontopia, rtm-tinytim, rtm-tmql, rubeus, rubinius-core-
 api, ruby-blockcache, ruby-debug-base, ruby-maven, ruby2java, rubydoop, rubyjedi-nokogiri_java, scala-inline, scala-library-jars, scriptty, slf4j, slf4j-jars, slyphon-
     zookeeper, slyphon-zookeeper_jar, smackr, smartimage, SNMP4JR, solr_sail, spiegela-jruby-httpclient, sproutcore, spymemcached, sqldroid, steamcannon-
 deltacloud-client, steamcannon-deltacloud-core, stilts-stomp-client, supermarket, svm_toolkit, swt, theduke, thick, to-javascript, torquebox-base, torquebox-
    cache, torquebox-configure, torquebox-container-foundation, torquebox-core, torquebox-messaging, torquebox-messaging-container, torquebox-naming,
 torquebox-naming-container, torquebox-security, torquebox-server, torquebox-vfs, torquebox-web, twitter4j4r, UDJrb, unageanu-javaclass, unimidi, universe-
 javascript, url_escape, weakling, webbit-jars, wildnet-jackson, wildnet-netty, wildnet-server, wildsonet-hazelcast, wildsonet-netty, wildsonet-server, wildsonet-
                                                                   streamer, wrest, wrong, xdojava, xqruby, zookeeper
actionmailer-javamail, active_documentum, activerecord-jdbc-adapter, activerecord-jdbcdbf-adapter, activerecord-jdbcderby-adapter, activerecord-jdbch2-
adapter, activerecord-jdbchsqldb-adapter, activerecord-jdbcmssql-adapter, activerecord-jdbcmysql-adapter, activerecord-jdbcpostgresql-adapter, activerecord-
    jdbcsqlite3-adapter, activerecord-netezza-adapter, activerecord-vertica-adapter, akephalos, akephalos-nerian, akephalos2, akka-actor-jars, akka-remote-jars,
    akubra_llstore_migrate, Antwrap, async-http-client-jars, atomic, atoulme-Antwrap, autotest-java, bbrowning-deltacloud-client, bbrowning-deltacloud-core,
   bcrypt-ruby, bee_java, berkeley-db-java-jars, bert, bio-maf, blockenspiel, boc, bond, bosdk, bouncy-castle-java, boxed-geminabox, brute-fuzzy, bryanl-gherkin,
 bson, buby, buildr, buildr-resolver, buildrizpack, butternut, capistrano-java, capybara-java_script_lint, carrierwave-neo4j, carrierwave_imagevoodoo, cassandra-
   jars, chrest, cloby, commons-io-jars, concurrently, contextual, coupler, cucumber-java, cucumber-jvm, cuke4duke, cuuid, dm-ldap-adapter, dm-lucene-adapter,
  do-jdbc_sqlserver, do_derby, do_h2, do_hsqldb, do_jdbc, do_mysql, do_openedge, do_oracle, do_postgres, do_sqlite3, do_sqlserver, doubleshot, dripdrop,
    dubious, duby, engineyard-visualvm, epall-limelight, errbit_zmq_handler, eurydice, euston, euston-daemons, euston-eventstore, euston-projections, euston-
   rabbitmq, euston-websites, eventmachine, excemel, faye-websocket, ffi, fig, file-find, fishwife, foreman, forkit, forkjoin, gamelan, gemshit, geoip-jars, get_back,
 gherkin, glassfish, gravitext-util, gravitext-xmlprod, grizzly, guava-jars, hadoop-find, hashdot-test-daemon, hiredis, hitimes, hope, hostor, hot_bunnies, hourglass,
 hpricot, http_parser.rb, inline_javascript, iudex, iudex-async-httpclient, iudex-barc, iudex-brutefuzzy-protobuf, iudex-brutefuzzy-service, iudex-char-detector,
 iudex-core, iudex-da, iudex-filter, iudex-html, iudex-http, iudex-http-test, iudex-httpclient-3, iudex-jetty-httpclient, iudex-rome, iudex-simhash, iudex-worker,
            ivy-jars, iyyov, jactive_support, java-autotest, java-inline, java2ruby-xmldsig, java_bin, java_inline, java_override, java_properties, java_streamify,
java_testing_guff, javabean_xml, javaclass, javaeye4r, javagems, javajake, javaobj, javaobjs, javaobs, javaparse, javasand, javascript-securehash-rails, javascript-state-
                machine-rails, javascript_auto_include, javascript_eraser, javascript_features, javascript_i18n, javascript_localize, javascript_safe_logger,
  javascript_util_asset_pack, javascripto, javascripto-rails, jdbc-derby, jdbc-hsqldb, jdbc-jtds, jdbc-openedge, jdbc-openedge-internal, jdbc-postgres, jdbc-sqlite3,



                                                No build tools!
      jedis-jars, jena-jruby, jessica, jettr, jetty, jetty-jsp, jgeoip, jms4r, jpdfer, jrack_handlers, jrtm, jruby-activemq, jruby-akka_jars, jruby-elasticsearch_jars, jruby-
      httpclient, jruby-launcher, jruby-management, jruby-metrics, jruby-pageant, jruby-vijava, jruby_gc_stats, jruby_sandbox, jruby_threach, jrubyconf-button,
  jsmetric4java, json, json-jruby, jsound, kb-activerecord-jdbc-adapter, kirk, kyotocabinet-java, ladle, latex-decode, launchy, libnotify, limelight, linecache, logback,
       logback-jars, looksee, lumix, mack-javascript, markdownj, maven_irb_plugin, metrics-core-jars, metrics-java, mguymon-buildr, mikka, mini_aether, mirah,
mirah_model, miso-java, mixology, mm_mq, mongrel, msgpack-idl-java, msgpack-jruby, multimeter, naether, nanoc-javascript-concatenator, neo4j, neo4j-admin,
      neo4j-advanced, neo4j-community, neo4j-core, neo4j-enterprise, neo4j-spatial, neo4j-will_paginate, neo4j-wrapper, netty-jars, ning-compress-jars, nio4r,
nokogiri, nokogiri-fitzsimmons, nokogiri-maven, nosqoop4u, ontomde-demo-java5, ontomde-java, ontomde-java-frontend, ontomde-uml2-java, ontomde-uml2-
               kbjava, open_nlp, pacer, pacer-dex, pacer-neo4j, pacer-orient, pelops-jars, persvr, pg_array_parser, protobuf-jars, pry, puma, qtjruby-core,
      qwirk_active_mq_adapter, qwirk_jms_adapter, rabbitmqadmin-cli, ragweed, rails_javascript_helpers, rakejava, rave, rcov, realityforge-jekyll, realityforge-
    jekylltask, redcar-bundles, redcar-clojure, redcar-filter-through-command, redcar-groovy, redcar-icons, redcar-javamateview, redcar-javascript, redcar-mirah,
        redcar-svnkit, redcar-xulrunner-win, RedCloth, refinerycms-javascripts, reigns, revo-nokogiri, rika, rjack-async-httpclient, rjack-commons-codec, rjack-
commons-dbcp, rjack-commons-dbutils, rjack-commons-pool, rjack-httpclient-3, rjack-httpclient-4, rjack-icu, rjack-jackson, rjack-jdom, rjack-jets3t, rjack-jetty,
     rjack-jetty-jsp, rjack-jms, rjack-jms-spec, rjack-logback, rjack-lucene, rjack-maven, rjack-mina, rjack-nekohtml, rjack-protobuf, rjack-qpid-client, rjack-rome,
  rjack-slf4j, rjack-solr, rjack-tarpit, rjack-xerces, rmagick4j, rmodbus, rtm-javatmapi, rtm-majortom, rtm-ontopia, rtm-tinytim, rtm-tmql, rubeus, rubinius-core-
 api, ruby-blockcache, ruby-debug-base, ruby-maven, ruby2java, rubydoop, rubyjedi-nokogiri_java, scala-inline, scala-library-jars, scriptty, slf4j, slf4j-jars, slyphon-
     zookeeper, slyphon-zookeeper_jar, smackr, smartimage, SNMP4JR, solr_sail, spiegela-jruby-httpclient, sproutcore, spymemcached, sqldroid, steamcannon-
 deltacloud-client, steamcannon-deltacloud-core, stilts-stomp-client, supermarket, svm_toolkit, swt, theduke, thick, to-javascript, torquebox-base, torquebox-
    cache, torquebox-configure, torquebox-container-foundation, torquebox-core, torquebox-messaging, torquebox-messaging-container, torquebox-naming,
 torquebox-naming-container, torquebox-security, torquebox-server, torquebox-vfs, torquebox-web, twitter4j4r, UDJrb, unageanu-javaclass, unimidi, universe-
 javascript, url_escape, weakling, webbit-jars, wildnet-jackson, wildnet-netty, wildnet-server, wildsonet-hazelcast, wildsonet-netty, wildsonet-server, wildsonet-
                                                                   streamer, wrest, wrong, xdojava, xqruby, zookeeper
Libraries
 Lucene     Neo4j
                         Selenium

47k libraries in Maven
Hadoop         EHCache

    JMonkeyEngine
                           Sitemesh
Languages/Polyglot
      Clojure                 Scala

                     Jython


Rhino/Nashorn/                Groovy
DynJS (JavaScript)
             Micro Focus JVM Visual COBOL
Polyglot

• Use right tool for the right job
• Running in the same VM
• Another dimension of libraries
GC
GC Matters

• Applications grow over time
• Ruby is very object-heavy
• Multiprocess multiplies the problem
• You will eventually have issues
JVM GC

• Wide array of options
• Many GCs to choose from
• Scales up to massive heaps
• Best GCs in the world!
OpenJDK GCs

• Parallel: multi-core stop-the-world
• Concurrent: STW young, concurrent old
• G1: concurrent young and old
• Serial: single-thread STW
Object Homogeneity

• Everything expressed as JVM objects
• Everything shares the same infrastructure
 • Including extensions, libraries, etc
• One GC to rule them all
 • And one standard memory model
gc_demo.rb


• Heavy GC, mix of old and young
• Steadily growing heap use
class Simple
  attr_accessor :next
end

top = Simple.new

puts Benchmark.measure {
  outer = 10
  total = 100000
  per = 100

  outer.times do
    total.times do
      per.times { Simple.new }
      s = Simple.new
      top.next = s
      top = s
    end
  end
}
Ruby 1.9.3              JRuby
8000



6000



4000



2000



   0
                    GC count
Ruby 1.9.3              JRuby
10000



 1000



  100



   10



    1
                     GC count
15
        Ruby 1.9.3               JRuby



11.25




  7.5




 3.75




   0
                     GC time %
Ruby 2.0.0                      JRuby
                               Time per GC versus heap usage
              300ms



              225ms
Time per GC




              150ms



              75ms



               0ms
               188KB/29MB                  27MB/127MB               199MB/238MB
                                   Heap usage (MRI/JRuby)
Ruby 2.0.0                      JRuby
                                   Time per GC versus heap usage

                   :-(

                   :-(
User Unhappiness




                   :-/

                   :-|

                   :-)
                   188KB/29MB                  27MB/127MB               199MB/238MB
                                       Heap usage (MRI/JRuby)
Ruby 2.0.0

                   4,000




                   3,000
Time Per GC (ms)




                   2,000




                   1,000




                      0
                           0M   1,250M       2,500M     3,750M   5,000M
                                            Heap Size
Findings

• Lower, more uniform GC times
• Reduced or eliminated pauses
• Very large heaps are no problem
• Predictable, consistent experience
Threads
Real Parallellism

• Ruby thread = JVM thread = native thread
• One process can use all cores
• One server can handle all requests
require 'benchmark'

ary = (1..1000000).to_a

loop {
  puts Benchmark.measure {
    10.times {
      ary.each {|i|}
    }
  }
}
require 'benchmark'

ary = (1..1000000).to_a

loop {
  puts Benchmark.measure {
    (1..10).map {
      Thread.new {
        ary.each {|i|}
      }
    }.map(&:join)
  }
}
Ruby 1.9
unthreaded
Ruby 1.9    Ruby 1.9
unthreaded   threaded
Ruby 1.9    Ruby 1.9
unthreaded   threaded




  JRuby
unthreaded
Ruby 1.9    Ruby 1.9
unthreaded   threaded




  JRuby        JRuby
unthreaded   threaded
threaded_reverse
                     Per-iteration time versus thread count
 0.8s



0.65s



 0.5s



0.35s



 0.2s
        one thread      two threads        three threads      four threads
Nonlinear?

• More work means more objects
• Allocation/GC needs memory bandwidth
• No different from multi-process
Tools
Profiling

• Java profilers
 • VisualVM,YourKit, NetBeans, JXInsight
• jruby [--profile | --profile.graph]
• jruby -Xreify.classes=true
• JVM command-line profilers
Monitoring

• Java Management Extensions (JMX)
 • Gems available for clients and servers
• jconsole and VisualVM
• Most servers provide additional tools
• New Relic, etc have JVM support
VisualVM

• CPU, memory, thread monitoring
• CPU and memory profiling
• VisualGC
• Heap analysis
JRuby Goodies
Scripting Java
JavaFX straight port



      Simple Clock
@minute_hand = Path.new.tap do |mh|       Draw minute hand
  mh.setFill(Color::BLACK)
  mh.getElements.add MoveTo.new(4, -4)
  mh.getElements.add ArcTo.new(-1, -1, 0, -4, -4, false, false)
  mh.getElements.add LineTo.new(0, -radius)
  mh.getTransforms.add Rotate.new
end
                                        Implement Java Event
class Refresher
  include EventHandler                        handler
  def handle(event); event.source.refresh; end
end
                                       refresh timeline every 1s
Timeline.new.tap do |time|
  time.setCycleCount Timeline::INDEFINITE
  time.getKeyFrames.add(Keyframe.new(Duration.millis(1000)),
                        Refresher.new)
  time.play
end
getFooBar -> fooBar
@minute_hand = Path.new.tap do |mh|
  mh.setFill(Color::BLACK)          was getElements
  mh.elements.add MoveTo.new(4, -4)
  mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false)
  mh.elements.add LineTo.new(0, -radius)
  mh.transforms.add Rotate.new
end                            was getTransforms
class Refresher
  include EventHandler
  def handle(event); event.source.refresh; end
end

Timeline.new.tap do |time|
  time.setCycleCount Timeline::INDEFINITE
  time.keyFrames.add(Keyframe.new(Duration.millis(1000)),
                     Refresher.new)
  time.play
end                  was getKeyFrames
setFoo(a) -> foo = a
@minute_hand = Path.new.tap do |mh|
  mh.fill = Color::BLACK            was setFill
  mh.elements.add MoveTo.new(4, -4)
  mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false)
  mh.elements.add LineTo.new(0, -radius)
  mh.transforms.add Rotate.new
end

class Refresher
  include EventHandler
  def handle(event); event.source.refresh; end
end

Timeline.new.tap do |time|
                                was setCycleCount
  time.cycleCount = Timeline::INDEFINITE
  time.keyFrames.add(Keyframe.new(Duration.millis(1000)),
                     Refresher.new)
  time.play
end
camelCase -> camel_case
@minute_hand = Path.new.tap do |mh|
  mh.fill = Color::BLACK
  mh.elements.add MoveTo.new(4, -4)
  mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false)
  mh.elements.add LineTo.new(0, -radius)
  mh.transforms.add Rotate.new
end

class Refresher
  include EventHandler
  def handle(event); event.source.refresh; end
end

Timeline.new.tap do |time|             was cycleCount
  time.cycle_count = Timeline::INDEFINITE
  time.key_frames.add(Keyframe.new(Duration.millis(1000)),
                      Refresher.new)
  time.play
end                                  was keyFrames
Procs as interfaces
@minute_hand = Path.new.tap do |mh|
  mh.fill = Color::BLACK
  mh.elements.add MoveTo.new(4, -4)
  mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false)
  mh.elements.add LineTo.new(0, -radius)
  mh.transforms.add Rotate.new
end                                   No more extra class
Timeline.new.tap do |time|
  time.cycle_count = Timeline::INDEFINITE
  time.key_frames.add Keyframe.new(Duration.millis(1000)) {refresh}
  time.play
end
Common Adornments
                     ‘add’ becomes ‘<<‘
@minute_hand = Path.new.tap do   |mh|
  mh.fill = Color::BLACK
  mh.elements << MoveTo.new(4,   -4)
  mh.elements << ArcTo.new(-1,   -1, 0, -4, -4, false, false)
  mh.elements << LineTo.new(0,   -radius)
  mh.transforms << Rotate.new
end

Timeline.new.tap do |time|
  time.cycle_count = Timeline::INDEFINITE
  time.key_frames << Keyframe.new(Duration.millis(1000)) {refresh}
  time.play
end
Purugin

• Minecraft scripting in JRuby
• Clean and simple DSL
• Purogo: LOGO for Minecraft
turtle("four-sided triangle") do |*args|
  dim = (args[0] || 5).to_i
  block_type = (args[1] || :stone).to_sym

  layer do
    4.times do |i|
      forward dim
      turnleft 90
    end
  end
  
  pivot do
    block :none
    forward 1
    turnleft 90
    forward 1
    turnup 90
    forward 1
    turndown 90
    turnright 90
    block block_type
  end

  block block_type
  (1...dim).step(2).to_a.reverse.each do |i|
    dim = i
    layer
    pivot
  end
end
Pimping a side-project


https://github.com/enebo/Purugin
Java Native Extensions
Native Extensions Suck
“Look, nobody enjoys
shooting penguins, but if
you have to shoot penguins,
well, you might as well
enjoy it.”
           - Free Waterfall Sr.
Flowchart of Shame
Can I write it in Ruby?               Script Java?
                               no
            yes                             no

    Does it need                     Can I use FFI?
    to be n times
       faster?                              no
                          no
                                    Native Extension
Java Native Extensions

• Written in Java
 • Have same performance as Java
 • Use same GC as JRuby
 • First Class Citizens
Performance
Go Java Go!                       300% for free
             JRuby 1.0.3 (bm_red_black_tree.rb)

 30



22.5



 15



 7.5



   0
  Java 1.4     Java 5                 Java 6             Java 7
Go JRuby Go!
                 OpenJDK 8 (bm_red_black_tree.rb)

8



6



4



2



0
 1.0.3   1.1.6          1.4.0       1.5.6           1.6.8   1.7.0
Severe gains???
                   OpenJDK 8 (bm_red_black_tree.rb)

  9
            Severe perf bottleneck(s)
6.75



 4.5



2.25



  0
   1.0.3   1.1.6          1.4.0       1.5.6           1.6.8   1.7.0
1.0.3 & red_black_tree
       -J-verbose:gc
          [GC (Allocation Failure) 223608K->96408K(330752K), 0.0159780 secs]
         [GC (Allocation Failure) 208920K->100792K(335168K), 0.0157550 secs]
         [GC (Allocation Failure) 213304K->105144K(332160K), 0.0181010 secs]
8.1s     [GC (Allocation Failure) 205112K->108920K(334400K), 0.0187580 secs]
         [GC (Allocation Failure) 208888K->112712K(329152K), 0.0154440 secs]
                                       +28 more


         [GC (Allocation Failure) 313780K->199892K(339072K), 0.0142010 secs]
         [GC (Allocation Failure) 318420K->204420K(331520K), 0.0175690 secs]
8.4s     [GC (Allocation Failure) 306948K->208316K(335680K), 0.0188120 secs]
           [Full GC (Ergonomics) 208316K->54991K(352256K), 0.2709750 secs]
          [GC (Allocation Failure) 157519K->58959K(349248K), 0.0120840 secs]
                                       +28 more



                              Moar Objects!
1.7.0 & red_black_tree
-J-verbose:gc
  [GC (Allocation Failure) 155729K->39697K(207296K), 0.0072730 secs]
                             0.963s
  [GC (Allocation Failure) 160785K->40657K(208320K), 0.0108620 secs]
                             0.968s
  [GC (Allocation Failure) 161745K->41649K(210112K), 0.0083760 secs]
                             0.968s
  [GC (Allocation Failure) 166193K->39729K(210688K), 0.0070670 secs]
                              0.99s
OpenJDK 8 (bm_red_black_tree.rb)

  3



2.25



 1.5



0.75



  0
   1.1.6   1.4.0          1.5.6          1.6.8   1.7.0
OpenJDK 8 (bm_red_black_tree.rb)

  3

                                      JVM Feature!
2.25



 1.5



0.75



  0
   1.1.6   1.4.0          1.5.6          1.6.8       1.7.0
Performance

• JRuby compiles Ruby to JVM bytecode
• JVM compiles bytecode to native
• Best JIT technology in the world
• Getting even better with invokedynamic
How to Optimize Ruby
• Do less work
 • Reduce dispatch and call overhead
 • Reduce memory overhead
• Find static patterns
 • Profile running code
 • Emit optimized version with guards
JVM Optimizations
• Profiling
 • Watch code, optimize hottest paths
• Inlining
 • Combine code, optimize as a whole
• Escape analysis
 • Eliminate transient objects
def foo; Object.new; end
def invoker; foo; end
i = 0
while i < 10000
  invoker
  i+=1
end
Inline foo into invoker
  def invoker; Object.new; end
  i = 0
  while i < 10000
    invoker
    i+=1
  end
Inline invoker into loop

  i = 0
  while i < 10000
    Object.new
    i+=1
  end
Object is transient

i = 0
while i < 10000

  i+=1
end
Loop does nothing

i = 10000
Variable i is never read
InvokeDynamic

• Java 7+ feature
• Allows us to teach JVM about Ruby
 • Dynamic calls can inline
 • Constants become truly constant
 • JVM’s best optimizations can work
Does It Work?
def foo; 1; end
def invoker; foo; end
N.times do
  i = 0
  while i < 10000
   invoker
   i+=1
  end
end
$ jruby -J-XX:+UnlockDiagnosticVMOptions 
         -J-XX:+PrintInlining 
         -J-XX:+PrintCompilation 
         script.rb
      79    1    b        java.lang.String::hashCode (55 bytes)
     109    2    b        java.util.Properties$LineReader::readLine (452 bytes)
                   @ 48  java.io.Reader::read (9 bytes)   never executed
                   @ 62  java.io.FilterInputStream::read (9 bytes)
                   @ 303  java.lang.System::arraycopy (0 bytes)    (intrinsic)
                   @ 388  java.io.Reader::read (9 bytes)   never executed
....
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
Does It Help?
JRuby/Java 6   JRuby/Java 7
JRuby/Java 6                   JRuby/Java 7
                        Times Faster than Ruby 1.9.3
  5



3.75



 2.5



1.25



  0
       base64      richards        neural      mandelbrot     redblack
JRuby/Java 6                     JRuby/Java 7
                            Times Faster than Ruby 1.9.3
  5



3.75



 2.5

                                    1.914          1.806
                    1.538                                         1.565
1.25   1.346




  0
         base64      richards          neural      mandelbrot      redblack
JRuby/Java 6                     JRuby/Java 7
                                 Times Faster than Ruby 1.9.3
  5


                                                                4.226           4.32
3.75
                                                 3.66
                                 3.44


 2.5           2.658


                                         1.914          1.806
                         1.538                                          1.565
1.25   1.346




  0
         base64           richards          neural      mandelbrot       redblack
smooth_sort
# Original Author: Keith Schwarz (htiek@cs.stanford.edu)
#
# Translated to Ruby by Chuck Remes (chuckremes on github)
#
# An implementation of Dijkstra's Smoothsort algorithm, a modification of
# heapsort that runs in O(n lg n) in the worst case, but O(n) if the data
# are already sorted. For more information about how this algorithm works
# and some of the details necessary for its proper operation, please see
#
#          http://www.keithschwarz.com/smoothsort/
Ruby 1.8.7   Ruby 1.9.3          Ruby 2.0.0   JRuby

100000



 75000



 50000



 25000

                                         19590.7
                        11439
              4750
     0
                         Iterations per second
And Rails?
Your Turn

• Try your apps on JRuby and tell us
• Turn on JRuby in @travisci
• Let us know what you think of JRuby
• Help us make JRuby even better!
• JRuby BOF in Room C at 6:30PM
JRUBY BOOK
Thank you!

• @headius
• jruby.org
• torquebox.org

Why JRuby? - RubyConf 2012

  • 1.
  • 2.
    Who? Thomas Charlie @tom_enebo @headius
  • 3.
  • 4.
    JRuby is Ruby!* 1.8.7 & 1.9.3 compatibility drop-in replacement * see next slide
  • 5.
    *caveats • Weak butimproving low-level UNIX stuff • No C extension support • Not maintained...off by default in 1.7 • Some features differ or unavailable • ObjectSpace, trace funcs, callcc, fork...
  • 6.
    JRuby is Ruby ...and then some?
  • 7.
    Announcing JRuby 1.7.0 •Ruby 1.9.3 compat (--1.8 for 1.8.7) • Java 7 invokedynamic support • Much awesomeness over 1.6.x
  • 8.
    Getting Started 1. Installa JVM 2. rvm install jruby 3. Profit! % jruby -e ‘puts “wowee”’
  • 9.
  • 10.
    JRuby Team Charlie Tom Nick Hiro Marcin Nahi Wayne Subbu Douglas Douglas Douglas Contribs Douglas Douglas Douglas Douglas Douglas Other Douglas OpenJDK Android JVMs
  • 11.
    JRuby JRuby Yoko JVM J. Rose OS (libc, ...)
  • 12.
    MRI nobu MRI OS (libc, ...)
  • 13.
    JRuby JRuby Yoko JVM J. Rose OS (libc, ...)
  • 14.
    We get itfor Free! JVM J. Rose Garbage Profiled Native JIT Optimizations Collection Native Tooling Cross Platform Threading
  • 15.
    Profile: John Rose • JVM Engineer since 1997 • Invented C* Language • JSR 292 lead
  • 16.
    JVM over time (whatif we were lazy?)
  • 17.
    Go Java Go! 300% for free JRuby 1.0.3 (bm_red_black_tree.rb) 30 22.5 15 7.5 0 Java 1.4 Java 5 Java 6 Java 7
  • 18.
    Go Java Go! 300% for free JRuby 1.0.3 (bm_red_black_tree.rb) MRI 1.8 30 22.5 15 7.5 0 Java 1.4 Java 5 Java 6 Java 7
  • 19.
  • 20.
  • 21.
    JVM is everywhere •Unix++, Windows • Exotic platforms: zLinux, OpenVMS, AS/400 • Mobile: Android’s Dalvik, Embedded JVMs
  • 23.
    Java bytecode == portability
  • 24.
    actionmailer-javamail, active_documentum, activerecord-jdbc-adapter,activerecord-jdbcdbf-adapter, activerecord-jdbcderby-adapter, activerecord-jdbch2- adapter, activerecord-jdbchsqldb-adapter, activerecord-jdbcmssql-adapter, activerecord-jdbcmysql-adapter, activerecord-jdbcpostgresql-adapter, activerecord- jdbcsqlite3-adapter, activerecord-netezza-adapter, activerecord-vertica-adapter, akephalos, akephalos-nerian, akephalos2, akka-actor-jars, akka-remote-jars, akubra_llstore_migrate, Antwrap, async-http-client-jars, atomic, atoulme-Antwrap, autotest-java, bbrowning-deltacloud-client, bbrowning-deltacloud-core, bcrypt-ruby, bee_java, berkeley-db-java-jars, bert, bio-maf, blockenspiel, boc, bond, bosdk, bouncy-castle-java, boxed-geminabox, brute-fuzzy, bryanl-gherkin, bson, buby, buildr, buildr-resolver, buildrizpack, butternut, capistrano-java, capybara-java_script_lint, carrierwave-neo4j, carrierwave_imagevoodoo, cassandra- jars, chrest, cloby, commons-io-jars, concurrently, contextual, coupler, cucumber-java, cucumber-jvm, cuke4duke, cuuid, dm-ldap-adapter, dm-lucene-adapter, do-jdbc_sqlserver, do_derby, do_h2, do_hsqldb, do_jdbc, do_mysql, do_openedge, do_oracle, do_postgres, do_sqlite3, do_sqlserver, doubleshot, dripdrop, dubious, duby, engineyard-visualvm, epall-limelight, errbit_zmq_handler, eurydice, euston, euston-daemons, euston-eventstore, euston-projections, euston- rabbitmq, euston-websites, eventmachine, excemel, faye-websocket, ffi, fig, file-find, fishwife, foreman, forkit, forkjoin, gamelan, gemshit, geoip-jars, get_back, gherkin, glassfish, gravitext-util, gravitext-xmlprod, grizzly, guava-jars, hadoop-find, hashdot-test-daemon, hiredis, hitimes, hope, hostor, hot_bunnies, hourglass, hpricot, http_parser.rb, inline_javascript, iudex, iudex-async-httpclient, iudex-barc, iudex-brutefuzzy-protobuf, iudex-brutefuzzy-service, iudex-char-detector, iudex-core, iudex-da, iudex-filter, iudex-html, iudex-http, iudex-http-test, iudex-httpclient-3, iudex-jetty-httpclient, iudex-rome, iudex-simhash, iudex-worker, ivy-jars, iyyov, jactive_support, java-autotest, java-inline, java2ruby-xmldsig, java_bin, java_inline, java_override, java_properties, java_streamify, java_testing_guff, javabean_xml, javaclass, javaeye4r, javagems, javajake, javaobj, javaobjs, javaobs, javaparse, javasand, javascript-securehash-rails, javascript-state- machine-rails, javascript_auto_include, javascript_eraser, javascript_features, javascript_i18n, javascript_localize, javascript_safe_logger, javascript_util_asset_pack, javascripto, javascripto-rails, jdbc-derby, jdbc-hsqldb, jdbc-jtds, jdbc-openedge, jdbc-openedge-internal, jdbc-postgres, jdbc-sqlite3, jedis-jars, jena-jruby, jessica, jettr, jetty, jetty-jsp, jgeoip, jms4r, jpdfer, jrack_handlers, jrtm, jruby-activemq, jruby-akka_jars, jruby-elasticsearch_jars, jruby- httpclient, jruby-launcher, jruby-management, jruby-metrics, jruby-pageant, jruby-vijava, jruby_gc_stats, jruby_sandbox, jruby_threach, jrubyconf-button, jsmetric4java, json, json-jruby, jsound, kb-activerecord-jdbc-adapter, kirk, kyotocabinet-java, ladle, latex-decode, launchy, libnotify, limelight, linecache, logback, logback-jars, looksee, lumix, mack-javascript, markdownj, maven_irb_plugin, metrics-core-jars, metrics-java, mguymon-buildr, mikka, mini_aether, mirah, mirah_model, miso-java, mixology, mm_mq, mongrel, msgpack-idl-java, msgpack-jruby, multimeter, naether, nanoc-javascript-concatenator, neo4j, neo4j-admin, neo4j-advanced, neo4j-community, neo4j-core, neo4j-enterprise, neo4j-spatial, neo4j-will_paginate, neo4j-wrapper, netty-jars, ning-compress-jars, nio4r, nokogiri, nokogiri-fitzsimmons, nokogiri-maven, nosqoop4u, ontomde-demo-java5, ontomde-java, ontomde-java-frontend, ontomde-uml2-java, ontomde-uml2- kbjava, open_nlp, pacer, pacer-dex, pacer-neo4j, pacer-orient, pelops-jars, persvr, pg_array_parser, protobuf-jars, pry, puma, qtjruby-core, qwirk_active_mq_adapter, qwirk_jms_adapter, rabbitmqadmin-cli, ragweed, rails_javascript_helpers, rakejava, rave, rcov, realityforge-jekyll, realityforge- jekylltask, redcar-bundles, redcar-clojure, redcar-filter-through-command, redcar-groovy, redcar-icons, redcar-javamateview, redcar-javascript, redcar-mirah, redcar-svnkit, redcar-xulrunner-win, RedCloth, refinerycms-javascripts, reigns, revo-nokogiri, rika, rjack-async-httpclient, rjack-commons-codec, rjack- commons-dbcp, rjack-commons-dbutils, rjack-commons-pool, rjack-httpclient-3, rjack-httpclient-4, rjack-icu, rjack-jackson, rjack-jdom, rjack-jets3t, rjack-jetty, rjack-jetty-jsp, rjack-jms, rjack-jms-spec, rjack-logback, rjack-lucene, rjack-maven, rjack-mina, rjack-nekohtml, rjack-protobuf, rjack-qpid-client, rjack-rome, rjack-slf4j, rjack-solr, rjack-tarpit, rjack-xerces, rmagick4j, rmodbus, rtm-javatmapi, rtm-majortom, rtm-ontopia, rtm-tinytim, rtm-tmql, rubeus, rubinius-core- api, ruby-blockcache, ruby-debug-base, ruby-maven, ruby2java, rubydoop, rubyjedi-nokogiri_java, scala-inline, scala-library-jars, scriptty, slf4j, slf4j-jars, slyphon- zookeeper, slyphon-zookeeper_jar, smackr, smartimage, SNMP4JR, solr_sail, spiegela-jruby-httpclient, sproutcore, spymemcached, sqldroid, steamcannon- deltacloud-client, steamcannon-deltacloud-core, stilts-stomp-client, supermarket, svm_toolkit, swt, theduke, thick, to-javascript, torquebox-base, torquebox- cache, torquebox-configure, torquebox-container-foundation, torquebox-core, torquebox-messaging, torquebox-messaging-container, torquebox-naming, torquebox-naming-container, torquebox-security, torquebox-server, torquebox-vfs, torquebox-web, twitter4j4r, UDJrb, unageanu-javaclass, unimidi, universe- javascript, url_escape, weakling, webbit-jars, wildnet-jackson, wildnet-netty, wildnet-server, wildsonet-hazelcast, wildsonet-netty, wildsonet-server, wildsonet- streamer, wrest, wrong, xdojava, xqruby, zookeeper
  • 25.
    actionmailer-javamail, active_documentum, activerecord-jdbc-adapter,activerecord-jdbcdbf-adapter, activerecord-jdbcderby-adapter, activerecord-jdbch2- adapter, activerecord-jdbchsqldb-adapter, activerecord-jdbcmssql-adapter, activerecord-jdbcmysql-adapter, activerecord-jdbcpostgresql-adapter, activerecord- jdbcsqlite3-adapter, activerecord-netezza-adapter, activerecord-vertica-adapter, akephalos, akephalos-nerian, akephalos2, akka-actor-jars, akka-remote-jars, akubra_llstore_migrate, Antwrap, async-http-client-jars, atomic, atoulme-Antwrap, autotest-java, bbrowning-deltacloud-client, bbrowning-deltacloud-core, bcrypt-ruby, bee_java, berkeley-db-java-jars, bert, bio-maf, blockenspiel, boc, bond, bosdk, bouncy-castle-java, boxed-geminabox, brute-fuzzy, bryanl-gherkin, bson, buby, buildr, buildr-resolver, buildrizpack, butternut, capistrano-java, capybara-java_script_lint, carrierwave-neo4j, carrierwave_imagevoodoo, cassandra- jars, chrest, cloby, commons-io-jars, concurrently, contextual, coupler, cucumber-java, cucumber-jvm, cuke4duke, cuuid, dm-ldap-adapter, dm-lucene-adapter, do-jdbc_sqlserver, do_derby, do_h2, do_hsqldb, do_jdbc, do_mysql, do_openedge, do_oracle, do_postgres, do_sqlite3, do_sqlserver, doubleshot, dripdrop, dubious, duby, engineyard-visualvm, epall-limelight, errbit_zmq_handler, eurydice, euston, euston-daemons, euston-eventstore, euston-projections, euston- rabbitmq, euston-websites, eventmachine, excemel, faye-websocket, ffi, fig, file-find, fishwife, foreman, forkit, forkjoin, gamelan, gemshit, geoip-jars, get_back, gherkin, glassfish, gravitext-util, gravitext-xmlprod, grizzly, guava-jars, hadoop-find, hashdot-test-daemon, hiredis, hitimes, hope, hostor, hot_bunnies, hourglass, hpricot, http_parser.rb, inline_javascript, iudex, iudex-async-httpclient, iudex-barc, iudex-brutefuzzy-protobuf, iudex-brutefuzzy-service, iudex-char-detector, iudex-core, iudex-da, iudex-filter, iudex-html, iudex-http, iudex-http-test, iudex-httpclient-3, iudex-jetty-httpclient, iudex-rome, iudex-simhash, iudex-worker, ivy-jars, iyyov, jactive_support, java-autotest, java-inline, java2ruby-xmldsig, java_bin, java_inline, java_override, java_properties, java_streamify, java_testing_guff, javabean_xml, javaclass, javaeye4r, javagems, javajake, javaobj, javaobjs, javaobs, javaparse, javasand, javascript-securehash-rails, javascript-state- machine-rails, javascript_auto_include, javascript_eraser, javascript_features, javascript_i18n, javascript_localize, javascript_safe_logger, javascript_util_asset_pack, javascripto, javascripto-rails, jdbc-derby, jdbc-hsqldb, jdbc-jtds, jdbc-openedge, jdbc-openedge-internal, jdbc-postgres, jdbc-sqlite3, No build tools! jedis-jars, jena-jruby, jessica, jettr, jetty, jetty-jsp, jgeoip, jms4r, jpdfer, jrack_handlers, jrtm, jruby-activemq, jruby-akka_jars, jruby-elasticsearch_jars, jruby- httpclient, jruby-launcher, jruby-management, jruby-metrics, jruby-pageant, jruby-vijava, jruby_gc_stats, jruby_sandbox, jruby_threach, jrubyconf-button, jsmetric4java, json, json-jruby, jsound, kb-activerecord-jdbc-adapter, kirk, kyotocabinet-java, ladle, latex-decode, launchy, libnotify, limelight, linecache, logback, logback-jars, looksee, lumix, mack-javascript, markdownj, maven_irb_plugin, metrics-core-jars, metrics-java, mguymon-buildr, mikka, mini_aether, mirah, mirah_model, miso-java, mixology, mm_mq, mongrel, msgpack-idl-java, msgpack-jruby, multimeter, naether, nanoc-javascript-concatenator, neo4j, neo4j-admin, neo4j-advanced, neo4j-community, neo4j-core, neo4j-enterprise, neo4j-spatial, neo4j-will_paginate, neo4j-wrapper, netty-jars, ning-compress-jars, nio4r, nokogiri, nokogiri-fitzsimmons, nokogiri-maven, nosqoop4u, ontomde-demo-java5, ontomde-java, ontomde-java-frontend, ontomde-uml2-java, ontomde-uml2- kbjava, open_nlp, pacer, pacer-dex, pacer-neo4j, pacer-orient, pelops-jars, persvr, pg_array_parser, protobuf-jars, pry, puma, qtjruby-core, qwirk_active_mq_adapter, qwirk_jms_adapter, rabbitmqadmin-cli, ragweed, rails_javascript_helpers, rakejava, rave, rcov, realityforge-jekyll, realityforge- jekylltask, redcar-bundles, redcar-clojure, redcar-filter-through-command, redcar-groovy, redcar-icons, redcar-javamateview, redcar-javascript, redcar-mirah, redcar-svnkit, redcar-xulrunner-win, RedCloth, refinerycms-javascripts, reigns, revo-nokogiri, rika, rjack-async-httpclient, rjack-commons-codec, rjack- commons-dbcp, rjack-commons-dbutils, rjack-commons-pool, rjack-httpclient-3, rjack-httpclient-4, rjack-icu, rjack-jackson, rjack-jdom, rjack-jets3t, rjack-jetty, rjack-jetty-jsp, rjack-jms, rjack-jms-spec, rjack-logback, rjack-lucene, rjack-maven, rjack-mina, rjack-nekohtml, rjack-protobuf, rjack-qpid-client, rjack-rome, rjack-slf4j, rjack-solr, rjack-tarpit, rjack-xerces, rmagick4j, rmodbus, rtm-javatmapi, rtm-majortom, rtm-ontopia, rtm-tinytim, rtm-tmql, rubeus, rubinius-core- api, ruby-blockcache, ruby-debug-base, ruby-maven, ruby2java, rubydoop, rubyjedi-nokogiri_java, scala-inline, scala-library-jars, scriptty, slf4j, slf4j-jars, slyphon- zookeeper, slyphon-zookeeper_jar, smackr, smartimage, SNMP4JR, solr_sail, spiegela-jruby-httpclient, sproutcore, spymemcached, sqldroid, steamcannon- deltacloud-client, steamcannon-deltacloud-core, stilts-stomp-client, supermarket, svm_toolkit, swt, theduke, thick, to-javascript, torquebox-base, torquebox- cache, torquebox-configure, torquebox-container-foundation, torquebox-core, torquebox-messaging, torquebox-messaging-container, torquebox-naming, torquebox-naming-container, torquebox-security, torquebox-server, torquebox-vfs, torquebox-web, twitter4j4r, UDJrb, unageanu-javaclass, unimidi, universe- javascript, url_escape, weakling, webbit-jars, wildnet-jackson, wildnet-netty, wildnet-server, wildsonet-hazelcast, wildsonet-netty, wildsonet-server, wildsonet- streamer, wrest, wrong, xdojava, xqruby, zookeeper
  • 26.
    Libraries Lucene Neo4j Selenium 47k libraries in Maven Hadoop EHCache JMonkeyEngine Sitemesh
  • 27.
    Languages/Polyglot Clojure Scala Jython Rhino/Nashorn/ Groovy DynJS (JavaScript) Micro Focus JVM Visual COBOL
  • 28.
    Polyglot • Use righttool for the right job • Running in the same VM • Another dimension of libraries
  • 29.
  • 30.
    GC Matters • Applicationsgrow over time • Ruby is very object-heavy • Multiprocess multiplies the problem • You will eventually have issues
  • 31.
    JVM GC • Widearray of options • Many GCs to choose from • Scales up to massive heaps • Best GCs in the world!
  • 32.
    OpenJDK GCs • Parallel:multi-core stop-the-world • Concurrent: STW young, concurrent old • G1: concurrent young and old • Serial: single-thread STW
  • 33.
    Object Homogeneity • Everythingexpressed as JVM objects • Everything shares the same infrastructure • Including extensions, libraries, etc • One GC to rule them all • And one standard memory model
  • 34.
    gc_demo.rb • Heavy GC,mix of old and young • Steadily growing heap use
  • 35.
    class Simple   attr_accessor :next end top= Simple.new puts Benchmark.measure {   outer = 10   total = 100000   per = 100   outer.times do     total.times do       per.times { Simple.new }       s = Simple.new       top.next = s       top = s     end   end }
  • 36.
    Ruby 1.9.3 JRuby 8000 6000 4000 2000 0 GC count
  • 37.
    Ruby 1.9.3 JRuby 10000 1000 100 10 1 GC count
  • 38.
    15 Ruby 1.9.3 JRuby 11.25 7.5 3.75 0 GC time %
  • 39.
    Ruby 2.0.0 JRuby Time per GC versus heap usage 300ms 225ms Time per GC 150ms 75ms 0ms 188KB/29MB 27MB/127MB 199MB/238MB Heap usage (MRI/JRuby)
  • 40.
    Ruby 2.0.0 JRuby Time per GC versus heap usage :-( :-( User Unhappiness :-/ :-| :-) 188KB/29MB 27MB/127MB 199MB/238MB Heap usage (MRI/JRuby)
  • 41.
    Ruby 2.0.0 4,000 3,000 Time Per GC (ms) 2,000 1,000 0 0M 1,250M 2,500M 3,750M 5,000M Heap Size
  • 42.
    Findings • Lower, moreuniform GC times • Reduced or eliminated pauses • Very large heaps are no problem • Predictable, consistent experience
  • 43.
  • 44.
    Real Parallellism • Rubythread = JVM thread = native thread • One process can use all cores • One server can handle all requests
  • 45.
    require 'benchmark' ary =(1..1000000).to_a loop {   puts Benchmark.measure {     10.times {       ary.each {|i|}     }   } }
  • 46.
    require 'benchmark' ary =(1..1000000).to_a loop {   puts Benchmark.measure {     (1..10).map {       Thread.new {         ary.each {|i|}       }     }.map(&:join)   } }
  • 48.
  • 49.
    Ruby 1.9 Ruby 1.9 unthreaded threaded
  • 50.
    Ruby 1.9 Ruby 1.9 unthreaded threaded JRuby unthreaded
  • 51.
    Ruby 1.9 Ruby 1.9 unthreaded threaded JRuby JRuby unthreaded threaded
  • 52.
    threaded_reverse Per-iteration time versus thread count 0.8s 0.65s 0.5s 0.35s 0.2s one thread two threads three threads four threads
  • 53.
    Nonlinear? • More workmeans more objects • Allocation/GC needs memory bandwidth • No different from multi-process
  • 55.
  • 56.
    Profiling • Java profilers • VisualVM,YourKit, NetBeans, JXInsight • jruby [--profile | --profile.graph] • jruby -Xreify.classes=true • JVM command-line profilers
  • 57.
    Monitoring • Java ManagementExtensions (JMX) • Gems available for clients and servers • jconsole and VisualVM • Most servers provide additional tools • New Relic, etc have JVM support
  • 58.
    VisualVM • CPU, memory,thread monitoring • CPU and memory profiling • VisualGC • Heap analysis
  • 65.
  • 66.
  • 67.
  • 68.
    @minute_hand = Path.new.tapdo |mh| Draw minute hand mh.setFill(Color::BLACK) mh.getElements.add MoveTo.new(4, -4) mh.getElements.add ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.getElements.add LineTo.new(0, -radius) mh.getTransforms.add Rotate.new end Implement Java Event class Refresher include EventHandler handler def handle(event); event.source.refresh; end end refresh timeline every 1s Timeline.new.tap do |time| time.setCycleCount Timeline::INDEFINITE time.getKeyFrames.add(Keyframe.new(Duration.millis(1000)), Refresher.new) time.play end
  • 69.
    getFooBar -> fooBar @minute_hand= Path.new.tap do |mh| mh.setFill(Color::BLACK) was getElements mh.elements.add MoveTo.new(4, -4) mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.elements.add LineTo.new(0, -radius) mh.transforms.add Rotate.new end was getTransforms class Refresher include EventHandler def handle(event); event.source.refresh; end end Timeline.new.tap do |time| time.setCycleCount Timeline::INDEFINITE time.keyFrames.add(Keyframe.new(Duration.millis(1000)), Refresher.new) time.play end was getKeyFrames
  • 70.
    setFoo(a) -> foo= a @minute_hand = Path.new.tap do |mh| mh.fill = Color::BLACK was setFill mh.elements.add MoveTo.new(4, -4) mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.elements.add LineTo.new(0, -radius) mh.transforms.add Rotate.new end class Refresher include EventHandler def handle(event); event.source.refresh; end end Timeline.new.tap do |time| was setCycleCount time.cycleCount = Timeline::INDEFINITE time.keyFrames.add(Keyframe.new(Duration.millis(1000)), Refresher.new) time.play end
  • 71.
    camelCase -> camel_case @minute_hand= Path.new.tap do |mh| mh.fill = Color::BLACK mh.elements.add MoveTo.new(4, -4) mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.elements.add LineTo.new(0, -radius) mh.transforms.add Rotate.new end class Refresher include EventHandler def handle(event); event.source.refresh; end end Timeline.new.tap do |time| was cycleCount time.cycle_count = Timeline::INDEFINITE time.key_frames.add(Keyframe.new(Duration.millis(1000)), Refresher.new) time.play end was keyFrames
  • 72.
    Procs as interfaces @minute_hand= Path.new.tap do |mh| mh.fill = Color::BLACK mh.elements.add MoveTo.new(4, -4) mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.elements.add LineTo.new(0, -radius) mh.transforms.add Rotate.new end No more extra class Timeline.new.tap do |time| time.cycle_count = Timeline::INDEFINITE time.key_frames.add Keyframe.new(Duration.millis(1000)) {refresh} time.play end
  • 73.
    Common Adornments ‘add’ becomes ‘<<‘ @minute_hand = Path.new.tap do |mh| mh.fill = Color::BLACK mh.elements << MoveTo.new(4, -4) mh.elements << ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.elements << LineTo.new(0, -radius) mh.transforms << Rotate.new end Timeline.new.tap do |time| time.cycle_count = Timeline::INDEFINITE time.key_frames << Keyframe.new(Duration.millis(1000)) {refresh} time.play end
  • 74.
    Purugin • Minecraft scriptingin JRuby • Clean and simple DSL • Purogo: LOGO for Minecraft
  • 75.
    turtle("four-sided triangle") do|*args|   dim = (args[0] || 5).to_i   block_type = (args[1] || :stone).to_sym   layer do     4.times do |i|       forward dim       turnleft 90     end   end      pivot do     block :none     forward 1     turnleft 90     forward 1     turnup 90     forward 1     turndown 90     turnright 90     block block_type   end   block block_type   (1...dim).step(2).to_a.reverse.each do |i|     dim = i     layer     pivot   end end
  • 77.
  • 78.
  • 79.
    Native Extensions Suck “Look,nobody enjoys shooting penguins, but if you have to shoot penguins, well, you might as well enjoy it.” - Free Waterfall Sr.
  • 80.
    Flowchart of Shame CanI write it in Ruby? Script Java? no yes no Does it need Can I use FFI? to be n times faster? no no Native Extension
  • 81.
    Java Native Extensions •Written in Java • Have same performance as Java • Use same GC as JRuby • First Class Citizens
  • 82.
  • 83.
    Go Java Go! 300% for free JRuby 1.0.3 (bm_red_black_tree.rb) 30 22.5 15 7.5 0 Java 1.4 Java 5 Java 6 Java 7
  • 84.
    Go JRuby Go! OpenJDK 8 (bm_red_black_tree.rb) 8 6 4 2 0 1.0.3 1.1.6 1.4.0 1.5.6 1.6.8 1.7.0
  • 85.
    Severe gains??? OpenJDK 8 (bm_red_black_tree.rb) 9 Severe perf bottleneck(s) 6.75 4.5 2.25 0 1.0.3 1.1.6 1.4.0 1.5.6 1.6.8 1.7.0
  • 86.
    1.0.3 & red_black_tree -J-verbose:gc [GC (Allocation Failure) 223608K->96408K(330752K), 0.0159780 secs] [GC (Allocation Failure) 208920K->100792K(335168K), 0.0157550 secs] [GC (Allocation Failure) 213304K->105144K(332160K), 0.0181010 secs] 8.1s [GC (Allocation Failure) 205112K->108920K(334400K), 0.0187580 secs] [GC (Allocation Failure) 208888K->112712K(329152K), 0.0154440 secs] +28 more [GC (Allocation Failure) 313780K->199892K(339072K), 0.0142010 secs] [GC (Allocation Failure) 318420K->204420K(331520K), 0.0175690 secs] 8.4s [GC (Allocation Failure) 306948K->208316K(335680K), 0.0188120 secs] [Full GC (Ergonomics) 208316K->54991K(352256K), 0.2709750 secs] [GC (Allocation Failure) 157519K->58959K(349248K), 0.0120840 secs] +28 more Moar Objects!
  • 87.
    1.7.0 & red_black_tree -J-verbose:gc [GC (Allocation Failure) 155729K->39697K(207296K), 0.0072730 secs] 0.963s [GC (Allocation Failure) 160785K->40657K(208320K), 0.0108620 secs] 0.968s [GC (Allocation Failure) 161745K->41649K(210112K), 0.0083760 secs] 0.968s [GC (Allocation Failure) 166193K->39729K(210688K), 0.0070670 secs] 0.99s
  • 88.
    OpenJDK 8 (bm_red_black_tree.rb) 3 2.25 1.5 0.75 0 1.1.6 1.4.0 1.5.6 1.6.8 1.7.0
  • 89.
    OpenJDK 8 (bm_red_black_tree.rb) 3 JVM Feature! 2.25 1.5 0.75 0 1.1.6 1.4.0 1.5.6 1.6.8 1.7.0
  • 90.
    Performance • JRuby compilesRuby to JVM bytecode • JVM compiles bytecode to native • Best JIT technology in the world • Getting even better with invokedynamic
  • 91.
    How to OptimizeRuby • Do less work • Reduce dispatch and call overhead • Reduce memory overhead • Find static patterns • Profile running code • Emit optimized version with guards
  • 92.
    JVM Optimizations • Profiling • Watch code, optimize hottest paths • Inlining • Combine code, optimize as a whole • Escape analysis • Eliminate transient objects
  • 93.
    def foo; Object.new;end def invoker; foo; end i = 0 while i < 10000   invoker   i+=1 end
  • 94.
    Inline foo intoinvoker def invoker; Object.new; end i = 0 while i < 10000   invoker   i+=1 end
  • 95.
    Inline invoker intoloop i = 0 while i < 10000   Object.new   i+=1 end
  • 96.
    Object is transient i= 0 while i < 10000   i+=1 end
  • 97.
  • 98.
    Variable i isnever read
  • 99.
    InvokeDynamic • Java 7+feature • Allows us to teach JVM about Ruby • Dynamic calls can inline • Constants become truly constant • JVM’s best optimizations can work
  • 100.
  • 101.
    def foo; 1;end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end
  • 102.
    $ jruby -J-XX:+UnlockDiagnosticVMOptions -J-XX:+PrintInlining -J-XX:+PrintCompilation script.rb 79 1 b java.lang.String::hashCode (55 bytes) 109 2 b java.util.Properties$LineReader::readLine (452 bytes) @ 48 java.io.Reader::read (9 bytes) never executed @ 62 java.io.FilterInputStream::read (9 bytes) @ 303 java.lang.System::arraycopy (0 bytes) (intrinsic) @ 388 java.io.Reader::read (9 bytes) never executed ....
  • 103.
    def foo; 1;end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 104.
    def foo; 1;end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 105.
    def foo; 1;end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 106.
    def foo; 1;end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 107.
    def foo; 1;end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 108.
    def foo; 1;end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 109.
    def foo; 1;end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 110.
    def foo; 1;end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 111.
  • 113.
    JRuby/Java 6 JRuby/Java 7
  • 114.
    JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 5 3.75 2.5 1.25 0 base64 richards neural mandelbrot redblack
  • 115.
    JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 5 3.75 2.5 1.914 1.806 1.538 1.565 1.25 1.346 0 base64 richards neural mandelbrot redblack
  • 116.
    JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 5 4.226 4.32 3.75 3.66 3.44 2.5 2.658 1.914 1.806 1.538 1.565 1.25 1.346 0 base64 richards neural mandelbrot redblack
  • 117.
    smooth_sort # Original Author:Keith Schwarz ([email protected]) # # Translated to Ruby by Chuck Remes (chuckremes on github) # # An implementation of Dijkstra's Smoothsort algorithm, a modification of # heapsort that runs in O(n lg n) in the worst case, but O(n) if the data # are already sorted. For more information about how this algorithm works # and some of the details necessary for its proper operation, please see # # http://www.keithschwarz.com/smoothsort/
  • 118.
    Ruby 1.8.7 Ruby 1.9.3 Ruby 2.0.0 JRuby 100000 75000 50000 25000 19590.7 11439 4750 0 Iterations per second
  • 119.
  • 123.
    Your Turn • Tryyour apps on JRuby and tell us • Turn on JRuby in @travisci • Let us know what you think of JRuby • Help us make JRuby even better! • JRuby BOF in Room C at 6:30PM
  • 124.
  • 126.
    Thank you! • @headius •jruby.org • torquebox.org