Your SlideShare is downloading. ×
0
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
JRuby @ Boulder Ruby
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

JRuby @ Boulder Ruby

632

Published on

Re-introduction to JRuby as presented to the Boulder Ruby group on October 30, 2012.

Re-introduction to JRuby as presented to the Boulder Ruby group on October 30, 2012.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
632
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Nick Sieger@nicksieger
  • 2. (RE-)INTRO
  • 3. Ruby onthe JVM
  • 4. Best of Ruby and Java... Together!
  • 5. http://www.flickr.com/photos/texascooking/5864122096/
  • 6. COMPATIBILITY
  • 7. runs nearly all pure ruby coderuns 92% of rubyspec suiteruns ~30% of 1.9 test suite(even more with 1.8 mode)
  • 8. http://jruby.org/download rvm install jruby INSTALL gem install jruby-lint $ jrlint
  • 9. drawbacks
  • 10. startup timememory footprintnative codeno Kernel#fork
  • 11. PERFORMANCE
  • 12. GC.pauses = “no thanks”
  • 13. class Simple  attr_accessor :nextendtop = Simple.newputs 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}
  • 14. Ruby 1.9.3 JRuby8000600040002000 0 GC count
  • 15. Ruby 1.9.3 JRuby10000 1000 100 10 1 GC count
  • 16. 15 Ruby 1.9.3 JRuby129630 GC time %
  • 17. Time per GC versus heap usage300ms Ruby 2.0.0 JRuby225ms150ms75ms 0ms 188KB/29MB 27MB/127MB 199MB/238MB Heap usage (MRI/JRuby)
  • 18. REALTHREADS
  • 19. Ruby 1.9 Ruby 1.9unthreaded threaded JRuby JRubyunthreaded threaded
  • 20. sidekiq.org What if 1 Sidekiq process could do the work of 20 Resque or DelayedJob processes?
  • 21. COMPILER
  • 22. Ruby application code JVM bytecode Key Native code Ruby Ruby Ruby code code code Ruby Ruby JRuby JRuby JRuby code code Ruby JVM JVM JRuby JVM JRuby codeFull interpretation JRuby compiler HotSpot compiler Time
  • 23. BENCHMARKS
  • 24. Red-Black Tree54 ruby 1.9.3p286 jruby 1.7.0 java 1.6.0_293 jruby 1.7.0 java 1.7.0_09 jruby 1.7.0 java 1.7.0_09-b05 +indy210
  • 25. Times Faster than Ruby 1.9.3 5 JRuby/Java 6 JRuby/Java 7+indy 4.226 4.323.75 3.66 3.44 2.5 2.658 1.914 1.8061.25 1.538 1.565 1.346 0 base64 richards neural mandelbrot redblack
  • 26. Java 7
  • 27. Get JDK 7 (OSX too!)java.oracle.com
  • 28. INVOKEDYNAMIC
  • 29. experthuman.com/programming-with- nothing Tom Stuart @tomstuart
  • 30. # lambda-> x {}
  • 31. # callp[x]
  • 32. FIZZBUZZ
  • 33. (1..100).each do |n| if (n % 15).zero? puts FizzBuzz elsif (n % 3).zero? puts Fizz elsif (n % 5).zero? puts Buzz else puts n.to_s endend
  • 34. fizzbuzz = -> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x {f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p {p[-> x { -> y { x } } ] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { ->y { y } } ] }[-> p { p[-> x { -> y { y } } ] }[l]] }[l]][x][g]][-> l {-> p { p[-> x { -> y { x } } ] }[-> p { p[-> x { -> y { y } } ] }[l]]}[l]][y] }] } } } }][k][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y{ x } }][-> x { -> y { x } }]][-> l { -> x { -> l { -> x { -> x { -> y{ -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f {f[x][y] } } }[x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y {x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b{ b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y{ x } }] }[-> m { -> n { n[-> n { -> f { -> x { n[-> g { -> h {h[g[f]] } }][-> y { x }][-> y { y }] } } }][m] } }[m][n]] }}[m][n]][-> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x{ -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[f[-> n {-> p { -> x { p[n[p][x]] } } }[m]][n]][m][x] }][-> x { -> y { -> f {f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]] } } }][-> p {-> x { p[x] } }][-> p { -> x {p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]} }]][-> n { -> b {b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f{ -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f {-> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y} } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> f { -> x {n[-> g { -> h { h[g[f]] } }][-> y { x }][-> y { y }] } } }][m] }
  • 35. METHODHANDLES
  • 36. INVOKEDYNAMIC [bootstrapMethod]bootstrapMethod(): Call Site CallSite (once) target Method Handle
  • 37. package java.lang.invoke;public abstract class MethodHandle { public final native Object invoke(Object... args) throws Throwable;}
  • 38. LAMBDA p[x]
  • 39. methodHandle.invoke(x);
  • 40. java.lang.invoke. MethodHandles arrayElementGetter arrayElementSetter spreadInvoker exactInvoker invokerexplicitCastArguments permuteArguments constant identity insertArguments dropArguments dropArguments filterArguments filterReturnValue foldArguments guardWithTest catchException throwException
  • 41. String literal Constant lookup Other literalsInstance variablesMethod invocation Math operations
  • 42. IT’S A JVM WORLD
  • 43. DRIVE JAVAFROM RUBY
  • 44. require javarequire rubygemsrequire flying_saucerjava_import org.xhtmlrenderer.pdf.ITextRendererdocument = <<-HTML<html><body><h1>Hello Flying Saucer!</h1></body></html>HTMLFile.open("doc.pdf", "wb") do |out| renderer = ITextRenderer.new renderer.set_document_from_string document renderer.layout renderer.create_pdf out.to_outputstreamendsystem("open doc.pdf") jruby -S gem install flying_saucer to try this example.
  • 45. $ jruby saucer.rb
  • 46. DECORATEJAVA OBJECTS WITH JRUBY
  • 47. module java::util::Iterator include Enumerable def each while has_next yield self.next end endend
  • 48. DRIVE RUBY FROM JAVA(org.jruby.embed)
  • 49. import org.jruby.embed.ScriptingContainer;public class EmbedJRuby { public static void main(String[] args) { ScriptingContainer container = new ScriptingContainer(); container.runScriptlet("puts Hello from Ruby"); }}(defn -main "Call JRuby!" [& args] (doto (org.jruby.embed.ScriptingContainer.) (.runScriptlet "puts Hello from Ruby!")))
  • 50. JRuby + Clojure
  • 51. ;; examples.clj(def hmap (hash-map "foo" "FOO" "bar" "BAR" "baz" "BAZ"))(println hmap)(println (get hmap "bar"))(println (contains? hmap "foo"))
  • 52. # rubyJava::clojure.main.main(["./examples.clj"])
  • 53. github.com/ daveray/ familiar
  • 54. Familiar.with do # clojure.core functions here # ‘-’ replaced with ‘_’ # e.g. hash-map => hash_mapend
  • 55. Familiar.with do r = ref(nil) begin ref_set r, foo rescue puts "no transaction! #{$!}" end dosync do ref_set r, foo end p deref(r)end
  • 56. j.mp/ clojure-from-jruby
  • 57. FUTURE
  • 58. {,bugs,wiki,ci} jruby.org
  • 59. github.com/ jruby
  • 60. Thanks!

×