Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby Interpreters: MRI Vs. JRuby

Ruby Interpreters: MRI Vs. JRuby

Have you ever wondered what the deal is with JRuby? What is it? Why would you use it in the first place? In this talk, I’ll explain the basics concepts behind a Ruby interpreter and outline a few of the reasons why you may or may not want to consider using JRuby.

Katlyn Parvin

January 11, 2017
Tweet

More Decks by Katlyn Parvin

Other Decks in Programming

Transcript

  1. Interpreters Let’s learn a little about them! • Why do

    we need an interpreter? • How do they work? ?
  2. Interpreter A computer program that interprets and translates source code

    into a format that the computer can understand.
  3. To start at the beginning... we will have to travel

    back in time to the early 1940s • Before the first interpreter in 1958 programs were written in assembly • Assembly languages required a lot of knowledge about the hardware and were very error-prone • Programs needed to be written in a way that the processor could understand
  4. Ex. MIPS Assembly Language Load the data at location 32($s3)

    in memory to the local register $t0 Perform the addition of $t0 and $s2 and store the result in register $t0 Store the value of register $t0 to location 48($s3) in memory Ruby Program my_array[12] = 10 + my_array[8] Equivalent MIPS Program
  5. • Scans the entire program and translates it as a

    whole • Fast execution time • Compile once -> run many times Compiler • Translates the program one statement at a time • Slower execution time • Faster analysis of the program • Translates the source code every time it is run Interpreter Converting from high-level language or
  6. Step 1 Tokenize Breakdown the ruby code into structured data

    # Ruby Example x = 10 y = 5 puts x + y
  7. Step 2 Lexical Analysis Tagging each token as an identifier,

    operator or integer # Ruby Example x = 10 y = 5 puts x + y
  8. Step 3 Build a Abstract Syntax Tree Representation of your

    program in memory # Ruby Example x = 10 y = 5 puts x + y
  9. Step 4 Compile to Bytecode Run in YARV the ruby

    VM (Ruby 1.9+) # Ruby Example x = 10 y = 5 puts x + y
  10. If you want to learn more about interpreters... I would

    highly recommend this talk by Ryan Davis From the 2013 Golden Gate Ruby Conf https://youtu.be/RPxvx9OkNic
  11. MRI Matz’s Ruby Interpreter - Written in C by the

    core Ruby team - Sets the standard for the Ruby Language - Well maintained with more paid core team members than any other Ruby Implementation - Consistent release cycle - Most likely what you are using to interpret Ruby
  12. JRuby - Written in primarily java - Implemented on top

    of the JVM - Which means you can run Ruby code anywhere Java can run. - Ruby 2.3 Compatible - Actively being maintained - Supports true parallel multi-threading - Not all gems work with JRuby
  13. Cool things about JRuby • Use Java libraries ◦ Great

    for companies that maintain Java codebases ◦ Utilize 3rd party Java Libraries ▪ Ex. Android development (ruboto) • Use ruby in your Java files ◦ Ex. utilize a ruby codebase within an existing Java app • Allows for a lot more performance optimizations options ◦ Tuning the JIT compiler ◦ Threading
  14. True Multi-Threading • Ruby 1.8.7 the GIL (Global Interpreter Lock)

    prevent more than 1 thread of Ruby code to run at any time. • Ruby 1.9+ can use multiple OS threads for I/O bound operations, but we cannot have parallel ruby processes • JRuby can use true OS threads allowing us to utilize multiple CPUs http://www.restlessprogrammer.com/2013/02/multi-threading-in-jruby.html
  15. Other interpreters to keep an eye on... Designed by Matz

    to be an embeddable implementation of Ruby Ruby interpreter written in RPython Implementation of Ruby that implements a generic runtime for dynamic languages on top of a Low Level Virtual Machine (LLVM) mRuby Topaz Rubinius Many more...
  16. Thank you! Katlyn Parvin Director of Engineering @ Mavenlink We

    are hiring! www.mavenlink.com/careers @KatlynParvin [email protected]