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

Rubinius — seemingly the same but completely different

Rubinius — seemingly the same but completely different

Slides from a talk I delivered on 13.03.2013 at Munich Ruby Users Group meetup.

Jan Stępień

March 13, 2013
Tweet

More Decks by Jan Stępień

Other Decks in Programming

Transcript

  1. Table of contents 1. Philosophy 2. JIT compilation 3. Garbage

    collection 4. Multithreading 5. The real life
  2. Array#insert static VALUE rb_ary_insert(int argc, VALUE *argv, VALUE ary) {

    long pos; if (argc < 1) { rb_raise(rb_eArgError, ”wrong number of arguments”); } rb_ary_modify_check(ary); if (argc == 1) return ary; pos = NUM2LONG(argv[0]); if (pos == -1) { pos = RARRAY_LEN(ary); } if (pos < 0) { pos++; } rb_ary_splice(ary, pos, 0, rb_ary_new4(argc - 1, argv + 1)); return ary; } class Array def insert(idx, *items) Rubinius.check_frozen return self if items.length == 0 idx = Rubinius::Type.coerce_to idx, Fixnum, :to_int idx += (@total + 1) if idx < 0 if idx < 0 raise IndexError, ”#{idx} out of bounds” end self[idx, 0] = items self end end (redacted for the sake of brevity and legibility)
  3. Compilation according to MRI require ’sinatra’ get ’/ping’ do content_type

    ’text/pong’ ’pong’ end → call self :get '/ping' :args → putself putstring ”sinatra” send :require, 1, nil, 8 pop trace putself putstring ”/ping” send :get, 1, <c>, 8
  4. Compilation according to Rubinius . . . → putself putstring

    ”sinatra” send :require, 1, nil, 8 pop trace putself putstring ”/ping” send :get, 1, <c>, 8 → xor eax, eax test rax, rax je 0xf01dab1e pop rbp mov edi, 0x600d80 jmp rax nop dword ptr [rax+0x0] mov eax, 0x600d80
  5. Compilation according to Rubinius require ’sinatra’ get ’/ping’ do content_type

    ’text/pong’ ’pong’ end → xor eax, eax test rax, rax je 0xf01dab1e pop rbp mov edi, 0x600d80 jmp rax nop dword ptr [rax+0x0] mov eax, 0x600d80 LLVM
  6. Garbage collection in MRI Allocation ▶ A memory pool divided

    into blocks ▶ A list of unused chunks Freeing 1. Stop the virtual machine 2. Mark all active objects 3. Delete unmarked objects
  7. 20%

  8. 20%

  9. 5 ings You’ll Love About Rubinius — Brian Ford https://blog.engineyard.com/2009/5-things-youll-love-about-

    rubinius/ Garbage Collector – Dirkjan Bussink https://github.com/rubinius/rubinius/blob/master/web/doc/en/memory- system/garbage-collector.markdown
  10. $ time ruby threads.rb 30.73user 0.03system 0:31.45elapsed 97%CPU (0avgtext+0avgdata 5032maxresident)k

    2032inputs+0outputs (1major+1354minor)pagefaults $ time rbx threads.rb 20.53user 0.04system 0:10.92elapsed 188%CPU (0avgtext+0avgdata 34280maxresident)k 0inputs+0outputs (0major+9166minor)pagefaults
  11. A handful of benchmarks Real ▶ rails — 1 000

    requests to a simple Rails 3.2 application ▶ sinatra — 10 000 requests to a simple Sinatra app Unreal ▶ matrices — matrix multiplication (from The Computer Language Benchmarks Game) ▶ threads — as seen on an earlier slide
  12. 0 10 20 30 40 50 rails sinatra threads matrices

    rbx mri Time of execution [s] Rubinius: commit fd80bd compiled with GCC 4.7.2. MRI: Arch Linux x86-64 package, version 1.9.3_p362-1. Rails and Sinatra served using Thin. Rails and Sinatra tests were preceded with sending 1k unmeasured requests to warm up JIT and caches.
  13. ese slides were typeset with L A TEX. © 2013

    Jan Stępień. Some rights reserved.