Skip to content

Instantly share code, notes, and snippets.

$:.unshift("/Users/miloops/Workspace/github/miloops/rails/activerecord/lib")
$:.unshift("/Users/miloops/Workspace/github/railsarel/lib")
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => ":memory:"
)
ActiveRecord::Schema.define do
IM
| AR |
------------------------------------------------------------------
Model#id x100000 | 0.796 |
Model.new (instantiation) x10000 | 0.303 |
Model.new (setting attributes) x10000 | 0.746 |
Model.first x10000 | 3.740 |
Model.all limit(100) x1000 | 13.367 |
Model.all limit(100) with relationship x1000 | 16.412 |
Model.all limit(10,000) x10 | 12.141 |
rails/master
| AR |
------------------------------------------------------------------
Model#id x100000 | 0.726 |
Model.new (instantiation) x10000 | 0.296 |
Model.new (setting attributes) x10000 | 0.718 |
Model.first x10000 | 3.346 |
Model.all limit(100) x1000 | 8.772 |
class WeakHash
def initialize(cache = Hash.new)
@cache = cache
@key_map = {}
@rev_cache = Hash.new{|h,k| h[k] = {}}
@reclaim_value = lambda do |value_id|
if value = @rev_cache.delete(value_id)
value.each_key{|key| @cache.delete key}
end
end
class WeakHash
def initialize(cache = Hash.new)
@cache = cache
@key_map = {}
@reclaim_key = lambda do |key_id|
delete(@key_map[key_id]) unless @cache.empty?
end
end
def [](key)
-- create_table(:accounts)
-> 0.0264s
-- create_table(:posts)
-> 0.0008s
-- create_table(:comments)
-> 0.0010s
==================================================
ActiveRecord::IdentityMap.enabled: false
Objects:
Warmup: 1110266 allocations | 40078000 bytes
$:.unshift("/Users/miloops/Workspace/github/miloops/rails/activerecord/lib")
$:.unshift("/Users/miloops/Workspace/github/swistak/weakling/lib")
$:.unshift("/Users/miloops/Workspace/github/railsarel/lib")
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => ":memory:"
)
def instances(&block)
GC.enable_stats
GC.clear_stats
block.call
warmup_objs = GC.num_allocations
warmup_bytes = GC.allocated_size
GC.clear_stats
block.call
puts "=" * 50
puts "ActiveRecord::IdentityMap.enabled: #{ActiveRecord::IdentityMap.enabled}"
def instances(&block)
GC.enable_stats
GC.clear_stats
block.call
warmup_objs = GC.num_allocations
warmup_bytes = GC.allocated_size
GC.clear_stats
block.call
puts "=" * 50
puts "ActiveRecord::IdentityMap.enabled: #{ActiveRecord::IdentityMap.enabled}"
def instances(&block)
GC.enable_stats
GC.clear_stats
block.call
warmup_objs = GC.num_allocations
warmup_bytes = GC.allocated_size
GC.clear_stats
block.call
puts "=" * 50
puts "ActiveRecord::IdentityMap.enabled: #{ActiveRecord::IdentityMap.enabled}"