Top Banner
JUICY RUBY 2.1 David Paluy Jan 2014 Founder of Azorly @dpaluy blog: david.paluy.org
27

Juicy Ruby 2.1

Aug 26, 2014

Download

Self Improvement

David Paluy

Overview of Ruby 2.1 features
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Juicy Ruby 2.1

JUICY RUBY 2.1David Paluy Jan 2014 Founder of Azorly @dpaluy blog: david.paluy.org

Page 2: Juicy Ruby 2.1

AGENDA

• Overview

• Performance

• Internal Improvements

• Should we migrate?

Page 3: Juicy Ruby 2.1

POLL• Ruby 1.8.7

• JRuby

• Rubinius

• Ruby 1.9.2 -1.9.3

• Ruby 2.0.0

• Ruby 2.1.0

Page 4: Juicy Ruby 2.1

RUBY 2.1OVERVIEW • Refinements

Advice: Don’t use it, unless you really need it!

Page 5: Juicy Ruby 2.1

RUBY 2.1OVERVIEW • Decimals

!

• Required Keyword Arguments

Page 6: Juicy Ruby 2.1

RUBY 2.1 OVERVIEW• Method Definition returns Method Name

!

• StringScanner supports Named Captures(check references)

Page 7: Juicy Ruby 2.1

PERFORMANCE - HOW TO MEASURE

but better use:

Page 8: Juicy Ruby 2.1

HOW TO MEASURE - HITIMESgem install hitimes

Page 9: Juicy Ruby 2.1

RUBY 2.1 PERFORMANCE

Source: http://miguelcamba.com/blog/2013/10/05/benchmarking-the-ruby-2-dot-1-and-rubinius-2-dot-0/

Page 10: Juicy Ruby 2.1

RUBY 2.1 INTERNAL IMPROVEMENTS

• Profiling support

• Improved ObjectSpace

• Improved GC

• Improved method caching

Page 11: Juicy Ruby 2.1

PROFILING SUPPORT - (C API)stackprof (perftools.rb replacement) https://github.com/tmm1/stackprof

!

!

!

Sampling modes: cpu, wall, :object, :custom

Read more: http://tmm1.net/ruby21-profiling/

Page 12: Juicy Ruby 2.1
Page 13: Juicy Ruby 2.1

OBJECTSPACE - HEAP DEBUGGING UTILITIES

Page 14: Juicy Ruby 2.1

RGenGC: Restricted Generational Garbage Collection

New generational GC algorithm permits Write-barrier (WB) protected objects AND WB un-protected object in the same heap

Page 15: Juicy Ruby 2.1
Page 16: Juicy Ruby 2.1

• Separate Objects

!

!

• Shady Object points to new Object?We don’t know!

• Decide at Creation Class cares about WB and don’t cares about non-WB

• Normal objects can be changed to Shady objects

RGenGC - Key Idea

Page 17: Juicy Ruby 2.1

OLDGEN AND MINOR MARKING

!

!

• Only protected objects can be promoted to oldgen

• Unprotected objects cannot be promoted, but if referenced from oldgen they are added to a remembered set.

• Minor marks are much faster because they only have to traverse references from the remembered set

Page 18: Juicy Ruby 2.1

TUNING THE GC IN RUBY 2.1Memory allocation → GC • Every time allocate n size memory (call malloc(n))

increase malloc_increase with n

• If malloc_increase > malloc_limit, then cause GC

!

Adaptive tuning • If malloc_increase exceeds malloc_limit, then increase malloc_limit

(by a factor of GC_MALLOC_LIMIT_GROWTH_FACTOR) up to GC_MALLOC_LIMIT_MAX

Page 19: Juicy Ruby 2.1
Page 20: Juicy Ruby 2.1

GC ENVIRONMENT PARAMS

Page 21: Juicy Ruby 2.1

GITHUB TWEAKS

Page 22: Juicy Ruby 2.1
Page 23: Juicy Ruby 2.1

METHODS CACHERuby 2.1 introduces a hierarchical class cache similar

to the what Rubinius and JRuby use

Aman Gupta: “Early numbers show up to 5-10% improvements”

!

More improvements in Ruby 2.2

Page 24: Juicy Ruby 2.1

PRODUCTION READY?• breaks the faraday gem

• affects the sass gem

• segv inside active_support_4 and other gems

• Performance Patches by funny-falcon

Page 25: Juicy Ruby 2.1

PRODUCTION READY?!!

Aman Gupta’s summary: https://gist.github.com/tmm1/8393897

Github uses Ruby 2.1 in Production

Page 26: Juicy Ruby 2.1

REFERENCES• Konstantin Haase - http://rkh.im/ruby-2.1

• Aaron Patterson - https://practicingruby.com/articles/parsing-json-the-hard-way?u=90296723ac

• Hitimes - https://github.com/copiousfreetime/hitimes

• Ruby Benchmark - https://github.com/acangiano/ruby-benchmark-suite

• Aman Gupta:production summary - https://gist.github.com/tmm1/8393897Ruby 2.1 - http://tmm1.net/ruby21/

• Koichi Sasada - http://rvm.jp/~ko1/activities/rubyconf2013-ko1_pub.pdf

• James Golick - http://jamesgolick.com/2013/4/14/mris-method-caches.html

Page 27: Juicy Ruby 2.1

THANK YOU! @DPALUY