compatible, if something's broken tell us • Supports pure-Ruby gems, many extensions • We want to be a Ruby first! • It's a JVM language • Full access to the power of the JVM platform!
opportunities to contribute! • Learn more about how Ruby and JRuby work! • Help us keep up with Ruby development! • Profit! • We are always standing by on IRC, Gitter, Twitter to help you
pain for potential JRuby users • Common transitive dependency with custom API • Needed for discourse • C extension only until now… https://github.com/ohler55/oj
0.06 0.11 0.72 0.05 0.11 0.36 0.13 0.29 1.1 JRuby(oj) JRuby(json) MRI(oj) Million of loads per second (higher is better) Data from https://techblog.thescore.com/2014/05/23/benchmarking-json-generation-in-ruby/
2006 • Almost as long as Rails has existed! • Thousands of JRoR instances around the world • JRuby 9000, Ruby 2.4, 2.5 work slowed down Rails support • Rails 5.0 not supported for at least a year • ActiveRecord suffered the most
Practically useless • Like judging a person by how much they can bench press • JRuby has won microbenchmarks for years • Easier to isolate specific measurements • Great for exploring new runtimes and tech
JVM see through all the dynamic bits of Ruby • Added in Java 7, with much input and testing from JRuby • Steadily improving performance, reducing overhead • -Xcompile.invokedynamic • May be default soon!
= 0 y = 0 while y < size ci = (2.0*y/size)-1.0 x = 0 while x < size zrzr = zr = 0.0 zizi = zi = 0.0 cr = (2.0*x/size)-1.5 escape = 0b1 z = 0 while z < 50
allocated on assignment • Any unfrozen object can grow • Looks like a Hash • Inefficient for mostly-same keys • Array reduces cost, still high • Make them JVM fields! class Person # closest we get to a declaration attr_accessor :fname, :lname, :bdate def initialize(fname, lname, bdate) # encountered after first object # has already been constructed @fname, @lname, @bdate = fname, lname, bdate end def initialize_id @id ||= SecureRandom.uuid end end
Arrays are small + immutable or large + mutable • Large, mutable arrays will often continue to mutate • Manually optimized 1- and 2-element arrays using fields • Future: hook into Object Shaping for Array
• Largest CPU consumer by far • Heavy object churn, GC overhead • Create, read, and update measurements • If delete is your bottleneck, we need to talk • CRuby 2.5.1 vs JRuby 9.2 on JDK10
threads, so we need processes • Processes inevitably duplicate runtime state • Much effort and lots of money wasted • JRuby is a great answer! • Multi-threaded single process runs your whole site
400-500MB versus 50MB • Ten CRuby processes = 500MB • Ten JRuby threads = 400-500MB • May need to tell JVM a memory cap • For 100-way or 1000-way...you do the math ADD GRAPH
calculate_cost(c) total1 = c.add 1000, 1 total2 = c.add 2000, 2 total1 + total2 end def calculate_cost(c) total1 = 1000 + 1 total2 = 2000 + 2 total1 + total2 end Disclaimer: Ruby much easier to read than IR * c.add must always be call to same method on same type == monomorphic call