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

Ruby's bin men

Ruby's bin men

Garbage collection - longer version with sesame street characters

elise_huard

June 30, 2012
Tweet

More Decks by elise_huard

Other Decks in Programming

Transcript

  1. I am the smallest rails app! Here is my source

    code: %w(action_controller/railtie coderay).map &method(:require) run TheSmallestRailsApp ||= Class.new(Rails::Application) { config.secret_token = routes.append { root to: 'hello#world' }.inspect initialize! } class HelloController < ActionController::Base def world render inline: " <!DOCTYPE html> <title>The Smallest Rails App</title> <h3>I am the smallest rails app!</h3> <p>Here is my source code:</p> #{CodeRay.scan_file(__FILE__, :ruby).div(line_numbers: :table)} <a href='https://github.com/artemave/thesmallestrailsapp.com'>Make me smaller</a> " end end Make me smaller https://github.com/artemave/thesmallestrailsapp.com The smallest Rails app Saturday, 30 June 12
  2. The smallest Rails app {:TOTAL=>351159, :FREE=>-8392, :T_OBJECT=>218, :T_CLASS=>894, :T_MODULE=>138, :T_FLOAT=>20,

    :T_STRING=>219091 :T_REGEXP=>489 :T_ARRAY=>22848 :T_HASH=>4896 :T_STRUCT=>76 :T_BIGNUM=>66 :T_FILE=>330 :T_DATA=>7502, :T_MATCH=>651, :T_COMPLEX=>0, :T_RATIONAL=>57, :T_NODE=>102163, :T_ICLASS=>112} Saturday, 30 June 12
  3. Hi, I want some memory Normal object allocation Object.new GC

    here’s your pointer if the heap Saturday, 30 June 12
  4. Hi, I want some memory Normal object allocation Object.new GC

    obj = (VALUE)objspace- >heap.free_slots->freelist; Saturday, 30 June 12
  5. Mark Hi, I want some memory let me check ...

    Heap GC Object.new Saturday, 30 June 12
  6. Mark Hi, I want some memory let me check ...

    Heap GC Object.new M Saturday, 30 June 12
  7. Mark Hi, I want some memory let me check ...

    Heap GC Object.new M M Saturday, 30 June 12
  8. Mark Hi, I want some memory let me check ...

    Heap GC Object.new M M M Saturday, 30 June 12
  9. Mark Hi, I want some memory let me check ...

    Heap GC Object.new M M M M Saturday, 30 June 12
  10. Mark Heap GC Object.new Oh dear, there’s not that much

    space left M M M M Saturday, 30 June 12
  11. Mark Heap GC Object.new Oh dear, there’s not that much

    space left M M M M Saturday, 30 June 12
  12. Lazy sweep here’s the next free slot Heap freelist hello,

    I need memory GC Object.new M M M M Saturday, 30 June 12
  13. Bitmap Marking Heap M M M 0 0 1 1

    0 0 1 0 0 Bitmap Saturday, 30 June 12
  14. Bitmap Marking Heap 0 0 1 1 0 0 1

    0 0 Bitmap Saturday, 30 June 12
  15. Bitmap Marking Heap 0 0 1 1 0 0 1

    0 0 Bitmap copy on write friendly! Saturday, 30 June 12
  16. • Nursery • Young generation • Mature generation • (Large

    objects) Generational GC Saturday, 30 June 12
  17. • Generational: • Young (eden - Survivor1 - Survivor2) •

    Tenured • Permanent Area • minor/major garbage collection JVM Saturday, 30 June 12
  18. Total: 28 samples 4 14.3% 14.3% 4 14.3% garbage_collector 2

    7.1% 21.4% 2 7.1% ActionView::Context#_prepare_context 2 7.1% 28.6% 2 7.1% ActionView::Renderer#_template_renderer 2 7.1% 35.7% 3 10.7% CodeRay::Scanners::Ruby#scan_tokens 2 7.1% 42.9% 2 7.1% Kernel#require 2 7.1% 50.0% 3 10.7% Module#encoder 2 7.1% 57.1% 2 7.1% String#scan 1 3.6% 60.7% 1 3.6% AbstractController::Rendering#view_renderer 1 3.6% 64.3% 2 7.1% AbstractController::ViewPaths#lookup_context CPU Saturday, 30 June 12
  19. Total: 42960 samples 6544 15.2% 15.2% 6665 15.5% Kernel#require 3781

    8.8% 24.0% 6439 15.0% Module#encoder 3539 8.2% 32.3% 5997 14.0% CodeRay::Scanners::Ruby#scan_tokens 2860 6.7% 38.9% 4996 11.6% String#scan 2743 6.4% 45.3% 3319 7.7% CodeRay::Encoders::HTML#finish 2645 6.2% 51.5% 3604 8.4% AbstractController::ViewPaths#lookup_context 2382 5.5% 57.0% 22608 52.6% CodeRay::Encoders::Encoder#encode 2156 5.0% 62.0% 2837 6.6% ActionView::Renderer#_template_renderer 1815 4.2% 66.3% 7685 17.9% CodeRay::Encoders::HTML#setup 1090 2.5% 68.8% 1159 2.7% ActionView::Context#_prepare_context 1078 2.5% 71.3% 1079 2.5% Module#module_eval 983 2.3% 73.6% 1069 2.5% Module#instrumenter Object allocation Saturday, 30 June 12
  20. #define GC_PROFILE_MORE_DETAIL 1 ... #define GC_NOTICE 1 22 GC during

    init with default ruby 1.9.3-rc1 Saturday, 30 June 12
  21. symbols class variables global variables huge data structures kept in

    memory “Leaking references” To avoid Saturday, 30 June 12
  22. • READ TEH CODES • read this: • (recent publications

    on garbage collection) To know more Saturday, 30 June 12