This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.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:" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |