Your SlideShare is downloading. ×
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Why Hashes Will Be Faster in Ruby 2.0
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Why Hashes Will Be Faster in Ruby 2.0

1,675

Published on

In this micro talk, I'll review the basic theory behind hash functions and hash tables, show you the new internal data structures that Ruby 2.0 uses to save keys and values, and present some …

In this micro talk, I'll review the basic theory behind hash functions and hash tables, show you the new internal data structures that Ruby 2.0 uses to save keys and values, and present some performance data that proves this optimization exists and how much time it will actually save you.

Published in: Technology, Sports
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,675
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
18
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. Why Hashes Will Be Faster in Ruby 2.0Pat Shaughnessyhttp://patshaughnessy.net@pat_shaughnessyMcKinsey & Co.
    • 2. h = {}=> {}h[:key] = value=> "value"h[:key]=> "value"
    • 3. Time to retrieve 10000 values (ms) 3 2.5 2 1.5 1 0.5 1 100 10,000 1,000,000 Hash size
    • 4. 0 1 2 3 4 5 6 7 8 9 10 st_table_entry hash key record next
    • 5. func(key) = hash
    • 6. :key.hash=> 4321153767602860351"abcdef".hash=> -1182018534040789564
    • 7. hash % 11 = bin index
    • 8. 0 1 2 3 4 5 6 7 8 9 10 st_table_entry hash key record next
    • 9. 0 1 2 3 4 5 6 7 8 9 10 st_table_entry st_table_entry hash hash key key record record next next
    • 10. 0 1 2 3 4 5 6 7 8 9 10 st_table_entry st_table_entry st_table_entry hash hash hash key key key record record record next next next
    • 11. 0 1 2 3 4 5 6 7 8 9 10 st_table_entry st_table_entry st_table_entry hash hash hash key key key record record record next next next st_table_entry hash key record next
    • 12. 0 1 2 3 4 5 6 7 8 9 10entry entry entry entry entry entry entry entry entry entry entryentry entry entry entry entry entry entry entry entry entry entryentry entry entry entry entry entry entry entry entry entry entryentry entry entry entry entry entry entry entryentry entry entry
    • 13. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entryentry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entryentry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entryentry entry entry entry entry entry entry entry
    • 14. Hashes in Ruby 2.0
    • 15. 0 1 2 3 4 5 6 7 8 9 10 malloc st_table_entry hash key record next Ruby 1.8, Ruby 1.9
    • 16. :key => :key2 => :key3 => :key4 => :key5 => :key6 => value value2 value3 value4 value5 value6 st_table_entry st_table_entry st_table_entry hash hash hash key key key record record record next next next Ruby 2.0 - first 6 elements
    • 17. Hashes are Arrays!
    • 18. Time to add 1 element 10,000 times (ms) 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Hash size
    • 19. 6% improvement0 Loading 10,000 small records
    • 20. 2.6% improvementRails App: Ruby Execution Time
    • 21. How many hashes?describe "GET index" do it "assigns all people as @people" do person = Person.create! valid_attributes get :index, {}, valid_session assigns(:people).should eq([person]) endend 5?
    • 22. How many hashes?describe "GET index" do it "assigns all people as @people" do person = Person.create! valid_attributes get :index, {}, valid_session assigns(:people).should eq([person]) endend 5 50?
    • 23. How many hashes?describe "GET index" do it "assigns all people as @people" do person = Person.create! valid_attributes get :index, {}, valid_session assigns(:people).should eq([person]) endend 50 409!
    • 24. http://patshaughnessy.net/ruby-under-a-microscope

    ×