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.
9. 0 1 2 3 4 5 6 7 8 9 10
st_table_entry
hash
key
record
next
10. 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
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
12. 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
17. :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
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])
end
end
5?
24. 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])
end
end
5 50?
25. 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])
end
end
50 409!