SlideShare a Scribd company logo
Ruby on the JVM
  Kresten Krab Thorup, Ph.D.
         CTO, Trifork
A bit of history...
  Smalltalk
    Self            OTI Smalltalk
 Strongtalk          VisualAge

  HotSpot             IBM Java
              Sun             IBM
Adaptive Optimizations
• Key insight:   The VM knows more about
  your program than you do.
• Consequence: Let the VM adapt to
  program’s behavior
 • VM will observe, tally and measure
 • feed information into successive
    optimizations
Time/Space Trade Off
• Classical compiler “ideology”
 • “ahead of time” compilers don’t know
    which parts of the code to optimize
 • gcc -O0 ... -O6
• Adaptive VMs
 • Affords letting the program run for a while
    to see where optimizations will pay off.
The Ruby Nature
• Program is created as it is being
  executed
 • Class / module declarations are really
   statements, not declarations.
 • Programming style employs meta
   programming extensively
• Very similar to Java, just “worse” :-)
“Just In Time” VMs
• For interpreted-style languages, perform
  compilation when the program definition is
  known.
• AFAIK Strongtalk/HotSpot brought the
  innovation of a two-level VM:
  • start interpreted (running byte code)
  • optimize adaptively
The “HotRuby” project
• Explore a “Server VM” for Ruby
  based on Java
• Assume “long running processes” where we
  can afford “slow start”.
• Assume aggressive memory usage
• Exploit knowledge of how the JVM
  optimizes programs
HotRuby Architecture
                  shared meta
                     model



    interpreter                 compiler


 ~MRI performance        ~2.5 x YARV performance
Design Philosophy

• Develop compiler and interpreter in
  parallel, and
• Favor compiler in the design of the runtime
  meta model
• Make trade-offs that reduce memory usage
• Write as much as possible in Ruby itself
Major Head Aches
• Method invocation
 • Calling “virtual” methods is slow
 • Program can change in many ways while
    running


• Memory management
 • Garbage collection is a resource hog
Naive Implementation

class RubyObject {
   RubyClass isa;
   HashTable<String,RubyObject> ivars;
   boolean frozen, tainted;
}
Naive Implementation
class RubyModule extends RubyObject {
  RubyVM vm;
  List<RubyModule> included_modules;
  HashTable<String,Callable> imethods;
  HashTable<String,Callable> mmethods;
  HashTable<String,RubyObject> constants;
}

class RubyClass extends RubyModule {
  RubyClass super_class;
}
Naive Implementation

class Callable {
   RubyObject call(RubyObject self,
                   RubyObject[] args,
                   RubyBlock block,
                   CallContext ctx);
}
Naive Implementation
  def m(obj)
    obj.foo(1, BAR)
  end

... translates into something like ...
  ctx = new MethodActivation(...);
  ctx.set_local(args[0]);
  obj = ctx.get_local(0)
  one = ctx.new_fixnum(1);
  bar = ctx.lookup_const(“BAR”);
  callable = obj.isa.imethods.get(“foo”);
  callable.call(obj, [one, bar], null, ctx)
Naive Implementation

       Ruby level


       Java level
Optimizing Calls

• Special-case common method names for
  core classes (new, +, -, [], ...): They turn into
  Java-level virtual calls.
• Compiled code is “specialized”, ...
• Method lookup is “compiled”, ...
Method Specialization
• Compiled code is “specialized” for the
  receiving type,
  • making self-calls non virtual,
  • reducing public/private/protected checks:
    Security-checks happen at method-
    lookup, not invocation time.
  • making constant lookups really constant.
Compiled Lookup
• With the “Naive” implementation, method
  lookup is data-driven (HashTable).
• Compiled lookup means that we dynamically
  generate/modify code, as the lookup table
  changes.
• Allows the JVM’s optimizing compiler to
  “know” how/when to eliminate or inline
  lookups.
Reduce Footprint

• Reduce size of heap for “active state” in a
  virtual machine
• Reduce “object churn”, i.e. rate of generated
  garbage.
Reducing Footprint
• Java objects already have an “isa” pointer!
  The implicit class reference.
• Use Java-level instance variables (in most
  cases)
• Eliminate the arguments array for method
  invocations (in most cases).
• Use Java-level local variables, removing the
  need for a “MethodActivation” object for
  each method call.
HotRuby Object
class RubyFoo {
   ObjectState state = null;
   RubyClass isa()
      { return state==null
          ? RubyClassFoo.class_object
          : state.singletonClass; }
}

class ObjectState {
    boolean frozen, tained;
    RubyClass singletonClass;
    HashTable<String,RubyObject> ivars;
}
HotRuby @ivars
• Generate Java classes lazily, upon first
  instantiation.
• At that point, analyze all applicable methods
  for reference to @ivars
• Generate Java-level ivars for all such
  references.
• Additional ivars go into ObjectState’s hash
  table.
Reducing Footprint
• The “Naive” implementation has an
  overhead per object of
     20 bytes + ~20 bytes / ivar
• HotRuby ideally reduces this to
     12 bytes + 4 bytes / ivar
• Heap of 100.000 object with an average 3
  ivars => 83% memory saving.
Use Java-Level locals
• The “cost” for having MethodActivation
  objects is both
 • The memory it consumes
 • The fact that such memory needs to be
    garbage collected
• Fall-back to MethodActivation object
  strategy for methods that call eval (and
  friends), and for local variables referenced
  from inner blocks.
HotRuby Status

• Runs basic Ruby programs (most
  importantly runit)
 • No Continuations, ObjectSpace,
    debugger, ... and many core classes
• Performance at 2.5 x YARV
• No, it does not run Rails.
Thanks
The Ruby
“Freak Show”
  ... getting started
Super Strange


def doit(x, y)
    super.doit(x, y)
end
Super Strange


def doit(x, y)
    super(x, y)
end
Super Strange


def doit(x, y)
    super
end
Super Strange


def doit(x, y=2, z=3)
    super
end
Super Strange


def doit(x, y=super, z=3)
    x+y+z
end
Super Strange


def doit(x, y=super(x,y,z), z=3)
    x+y+z
end
Thanks

More Related Content

What's hot

Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 TaiwanAutomating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Adler Hsieh
 
Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)
Tomer Gabel
 
Scalatra 2.2
Scalatra 2.2Scalatra 2.2
Scalatra 2.2
Ivan Porto Carrero
 
Event Driven Architecture with Apache Camel
Event Driven Architecture with Apache CamelEvent Driven Architecture with Apache Camel
Event Driven Architecture with Apache Camel
prajods
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
Junichi Ishida
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
Metosin Oy
 
JCR - Java Content Repositories
JCR - Java Content RepositoriesJCR - Java Content Repositories
JCR - Java Content Repositories
Carsten Ziegeler
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
Wen-Tien Chang
 
How to-node-core
How to-node-coreHow to-node-core
How to-node-core
IsaacSchlueter
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
Ruby projects of interest for DevOps
Ricardo Sanchez
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
krasserm
 
Rango
RangoRango
Applying the paradigms of core.async in Clojure and ClojureScript
Applying the paradigms of core.async in Clojure and ClojureScriptApplying the paradigms of core.async in Clojure and ClojureScript
Applying the paradigms of core.async in Clojure and ClojureScript
Julian Gamble
 
Rango
RangoRango
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
FuseSource.com
 
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Julian Gamble
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
Tomer Gabel
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Tools
guest05c09d
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
Claus Ibsen
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data binding
Alex Derkach
 

What's hot (20)

Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 TaiwanAutomating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
 
Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)
 
Scalatra 2.2
Scalatra 2.2Scalatra 2.2
Scalatra 2.2
 
Event Driven Architecture with Apache Camel
Event Driven Architecture with Apache CamelEvent Driven Architecture with Apache Camel
Event Driven Architecture with Apache Camel
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
 
JCR - Java Content Repositories
JCR - Java Content RepositoriesJCR - Java Content Repositories
JCR - Java Content Repositories
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
 
How to-node-core
How to-node-coreHow to-node-core
How to-node-core
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
Ruby projects of interest for DevOps
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
 
Rango
RangoRango
Rango
 
Applying the paradigms of core.async in Clojure and ClojureScript
Applying the paradigms of core.async in Clojure and ClojureScriptApplying the paradigms of core.async in Clojure and ClojureScript
Applying the paradigms of core.async in Clojure and ClojureScript
 
Rango
RangoRango
Rango
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Tools
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data binding
 

Viewers also liked

Ins Avis N4
Ins Avis N4Ins Avis N4
Ins Avis N4
marsetti
 
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Kresten Krab Thorup
 
Strade dipinte
Strade dipinteStrade dipinte
Strade dipinte
marsetti
 
Erjang - A JVM-based Erlang VM
Erjang - A JVM-based Erlang VMErjang - A JVM-based Erlang VM
Erjang - A JVM-based Erlang VM
Kresten Krab Thorup
 
Album 1 1976 1984
Album 1 1976 1984Album 1 1976 1984
Album 1 1976 1984
marsetti
 
Ins Avis N9
Ins Avis N9Ins Avis N9
Ins Avis N9
marsetti
 
Ins Avis N1
Ins Avis N1Ins Avis N1
Ins Avis N1
marsetti
 
Album 5 2006 2007
Album 5 2006   2007Album 5 2006   2007
Album 5 2006 2007marsetti
 
Storia_shay
Storia_shayStoria_shay
Storia_shay
marsetti
 

Viewers also liked (9)

Ins Avis N4
Ins Avis N4Ins Avis N4
Ins Avis N4
 
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
 
Strade dipinte
Strade dipinteStrade dipinte
Strade dipinte
 
Erjang - A JVM-based Erlang VM
Erjang - A JVM-based Erlang VMErjang - A JVM-based Erlang VM
Erjang - A JVM-based Erlang VM
 
Album 1 1976 1984
Album 1 1976 1984Album 1 1976 1984
Album 1 1976 1984
 
Ins Avis N9
Ins Avis N9Ins Avis N9
Ins Avis N9
 
Ins Avis N1
Ins Avis N1Ins Avis N1
Ins Avis N1
 
Album 5 2006 2007
Album 5 2006   2007Album 5 2006   2007
Album 5 2006 2007
 
Storia_shay
Storia_shayStoria_shay
Storia_shay
 

Similar to Ruby on the JVM

The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
Burke Libbey
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
Ryan Cuprak
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfaces
juanvazquezslides
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
Atlassian
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
CodeFest
 
Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門
Wen-Tien Chang
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
Alex Payne
 
Ricardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devopsRicardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devops
SVDevOps
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Nayden Gochev
 
遇見 Ruby on Rails
遇見 Ruby on Rails遇見 Ruby on Rails
遇見 Ruby on Rails
Wen-Tien Chang
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
Charles Nutter
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?
Joshua Ballanco
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
gicappa
 
Invokedynamic / JSR-292
Invokedynamic / JSR-292Invokedynamic / JSR-292
Invokedynamic / JSR-292
ytoshima
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
Mario Camou Riveroll
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter Slides
Alexandra Masterson
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
Charles Nutter
 

Similar to Ruby on the JVM (20)

The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfaces
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Ricardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devopsRicardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devops
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
 
遇見 Ruby on Rails
遇見 Ruby on Rails遇見 Ruby on Rails
遇見 Ruby on Rails
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Invokedynamic / JSR-292
Invokedynamic / JSR-292Invokedynamic / JSR-292
Invokedynamic / JSR-292
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter Slides
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 

Recently uploaded

Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 

Recently uploaded (20)

Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 

Ruby on the JVM

  • 1. Ruby on the JVM Kresten Krab Thorup, Ph.D. CTO, Trifork
  • 2. A bit of history... Smalltalk Self OTI Smalltalk Strongtalk VisualAge HotSpot IBM Java Sun IBM
  • 3. Adaptive Optimizations • Key insight: The VM knows more about your program than you do. • Consequence: Let the VM adapt to program’s behavior • VM will observe, tally and measure • feed information into successive optimizations
  • 4. Time/Space Trade Off • Classical compiler “ideology” • “ahead of time” compilers don’t know which parts of the code to optimize • gcc -O0 ... -O6 • Adaptive VMs • Affords letting the program run for a while to see where optimizations will pay off.
  • 5. The Ruby Nature • Program is created as it is being executed • Class / module declarations are really statements, not declarations. • Programming style employs meta programming extensively • Very similar to Java, just “worse” :-)
  • 6. “Just In Time” VMs • For interpreted-style languages, perform compilation when the program definition is known. • AFAIK Strongtalk/HotSpot brought the innovation of a two-level VM: • start interpreted (running byte code) • optimize adaptively
  • 7. The “HotRuby” project • Explore a “Server VM” for Ruby based on Java • Assume “long running processes” where we can afford “slow start”. • Assume aggressive memory usage • Exploit knowledge of how the JVM optimizes programs
  • 8. HotRuby Architecture shared meta model interpreter compiler ~MRI performance ~2.5 x YARV performance
  • 9. Design Philosophy • Develop compiler and interpreter in parallel, and • Favor compiler in the design of the runtime meta model • Make trade-offs that reduce memory usage • Write as much as possible in Ruby itself
  • 10. Major Head Aches • Method invocation • Calling “virtual” methods is slow • Program can change in many ways while running • Memory management • Garbage collection is a resource hog
  • 11. Naive Implementation class RubyObject { RubyClass isa; HashTable<String,RubyObject> ivars; boolean frozen, tainted; }
  • 12. Naive Implementation class RubyModule extends RubyObject { RubyVM vm; List<RubyModule> included_modules; HashTable<String,Callable> imethods; HashTable<String,Callable> mmethods; HashTable<String,RubyObject> constants; } class RubyClass extends RubyModule { RubyClass super_class; }
  • 13. Naive Implementation class Callable { RubyObject call(RubyObject self, RubyObject[] args, RubyBlock block, CallContext ctx); }
  • 14. Naive Implementation def m(obj) obj.foo(1, BAR) end ... translates into something like ... ctx = new MethodActivation(...); ctx.set_local(args[0]); obj = ctx.get_local(0) one = ctx.new_fixnum(1); bar = ctx.lookup_const(“BAR”); callable = obj.isa.imethods.get(“foo”); callable.call(obj, [one, bar], null, ctx)
  • 15. Naive Implementation Ruby level Java level
  • 16. Optimizing Calls • Special-case common method names for core classes (new, +, -, [], ...): They turn into Java-level virtual calls. • Compiled code is “specialized”, ... • Method lookup is “compiled”, ...
  • 17. Method Specialization • Compiled code is “specialized” for the receiving type, • making self-calls non virtual, • reducing public/private/protected checks: Security-checks happen at method- lookup, not invocation time. • making constant lookups really constant.
  • 18. Compiled Lookup • With the “Naive” implementation, method lookup is data-driven (HashTable). • Compiled lookup means that we dynamically generate/modify code, as the lookup table changes. • Allows the JVM’s optimizing compiler to “know” how/when to eliminate or inline lookups.
  • 19. Reduce Footprint • Reduce size of heap for “active state” in a virtual machine • Reduce “object churn”, i.e. rate of generated garbage.
  • 20. Reducing Footprint • Java objects already have an “isa” pointer! The implicit class reference. • Use Java-level instance variables (in most cases) • Eliminate the arguments array for method invocations (in most cases). • Use Java-level local variables, removing the need for a “MethodActivation” object for each method call.
  • 21. HotRuby Object class RubyFoo { ObjectState state = null; RubyClass isa() { return state==null ? RubyClassFoo.class_object : state.singletonClass; } } class ObjectState { boolean frozen, tained; RubyClass singletonClass; HashTable<String,RubyObject> ivars; }
  • 22. HotRuby @ivars • Generate Java classes lazily, upon first instantiation. • At that point, analyze all applicable methods for reference to @ivars • Generate Java-level ivars for all such references. • Additional ivars go into ObjectState’s hash table.
  • 23. Reducing Footprint • The “Naive” implementation has an overhead per object of 20 bytes + ~20 bytes / ivar • HotRuby ideally reduces this to 12 bytes + 4 bytes / ivar • Heap of 100.000 object with an average 3 ivars => 83% memory saving.
  • 24. Use Java-Level locals • The “cost” for having MethodActivation objects is both • The memory it consumes • The fact that such memory needs to be garbage collected • Fall-back to MethodActivation object strategy for methods that call eval (and friends), and for local variables referenced from inner blocks.
  • 25. HotRuby Status • Runs basic Ruby programs (most importantly runit) • No Continuations, ObjectSpace, debugger, ... and many core classes • Performance at 2.5 x YARV • No, it does not run Rails.
  • 27. The Ruby “Freak Show” ... getting started
  • 28. Super Strange def doit(x, y) super.doit(x, y) end
  • 29. Super Strange def doit(x, y) super(x, y) end
  • 31. Super Strange def doit(x, y=2, z=3) super end
  • 32. Super Strange def doit(x, y=super, z=3) x+y+z end
  • 33. Super Strange def doit(x, y=super(x,y,z), z=3) x+y+z end