Juicy Ruby 2.1
-
Upload
david-paluy -
Category
Self Improvement
-
view
801 -
download
0
description
Transcript of Juicy Ruby 2.1
JUICY RUBY 2.1David Paluy Jan 2014 Founder of Azorly @dpaluy blog: david.paluy.org
AGENDA
• Overview
• Performance
• Internal Improvements
• Should we migrate?
POLL• Ruby 1.8.7
• JRuby
• Rubinius
• Ruby 1.9.2 -1.9.3
• Ruby 2.0.0
• Ruby 2.1.0
RUBY 2.1OVERVIEW • Refinements
Advice: Don’t use it, unless you really need it!
RUBY 2.1OVERVIEW • Decimals
!
• Required Keyword Arguments
RUBY 2.1 OVERVIEW• Method Definition returns Method Name
!
• StringScanner supports Named Captures(check references)
PERFORMANCE - HOW TO MEASURE
but better use:
HOW TO MEASURE - HITIMESgem install hitimes
RUBY 2.1 PERFORMANCE
…
Source: http://miguelcamba.com/blog/2013/10/05/benchmarking-the-ruby-2-dot-1-and-rubinius-2-dot-0/
RUBY 2.1 INTERNAL IMPROVEMENTS
• Profiling support
• Improved ObjectSpace
• Improved GC
• Improved method caching
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/
OBJECTSPACE - HEAP DEBUGGING UTILITIES
RGenGC: Restricted Generational Garbage Collection
New generational GC algorithm permits Write-barrier (WB) protected objects AND WB un-protected object in the same heap
• 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
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
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
GC ENVIRONMENT PARAMS
GITHUB TWEAKS
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
PRODUCTION READY?• breaks the faraday gem
• affects the sass gem
• segv inside active_support_4 and other gems
• Performance Patches by funny-falcon
PRODUCTION READY?!!
Aman Gupta’s summary: https://gist.github.com/tmm1/8393897
Github uses Ruby 2.1 in Production
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
THANK YOU! @DPALUY