Created
November 17, 2016 06:47
-
-
Save splattael/dad289f60b67f1f4949631afdf32b2b1 to your computer and use it in GitHub Desktop.
dry memory allocations
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
require "bundler/inline" | |
gem "dry-types" | |
gem "dry-struct" | |
gem "allocation_tracer" | |
require "dry-types" | |
require "dry-struct" | |
module Types | |
class Agent < Dry::Struct | |
include Dry::Types.module | |
constructor_type :strict | |
attribute :budget, Strict::Int | |
end | |
class Success < Dry::Struct | |
include Dry::Types.module | |
constructor_type :strict | |
attribute :match_day_uid, Strict::String | |
attribute :agent, Types::Agent | |
end | |
end | |
GC.disable | |
require "allocation_tracer" | |
ObjectSpace::AllocationTracer.setup(%i{path line type}) | |
ObjectSpace::AllocationTracer.start | |
1000.times do | |
Types::Success.new( | |
:match_day_uid => "string", | |
:agent => Types::Agent.new( | |
:budget => 1 | |
) | |
) | |
end | |
at_exit { | |
results = ObjectSpace::AllocationTracer.stop | |
results.sort_by { |k, v| v[0] }.each { |(filename, line, type), v| | |
$LOAD_PATH.detect do |path| | |
regexp = %r{#{Regexp.quote(path)}/?} | |
filename.gsub!(regexp, "") | |
end | |
puts "%60s:%-3d %8s %s" % [ filename, line, type, v.join("\t") ] | |
} | |
p :total => results.inject(0) { |sum, (k, v)| sum + v[0] } | |
} |
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
inline.rb:33 T_IMEMO 1 0 0 0 0 0 | |
dry/struct/class_interface.rb:74 T_IMEMO 1 0 0 0 0 0 | |
dry/struct/class_interface.rb:77 T_IMEMO 1 0 0 0 0 0 | |
dry/types/decorator.rb:28 T_IMEMO 1 0 0 0 0 0 | |
inline.rb:39 T_DATA 1 0 0 0 0 0 | |
inline.rb:0 T_ARRAY 1 0 0 0 0 0 | |
dry/types/hash/schema.rb:96 T_IMEMO 2 0 0 0 0 0 | |
dry/types/hash/schema.rb:52 T_IMEMO 2 0 0 0 0 0 | |
inline.rb:32 T_STRING 1000 0 0 0 0 0 | |
inline.rb:33 T_HASH 1000 0 0 0 0 0 | |
inline.rb:31 T_HASH 1000 0 0 0 0 0 | |
dry/types/hash/schema.rb:92 T_HASH 2000 0 0 0 0 0 | |
dry/types/hash/schema.rb:60 T_HASH 2000 0 0 0 0 0 | |
dry/logic/rule.rb:0 T_ARRAY 2000 0 0 0 0 0 | |
dry/logic/rule.rb:47 T_OBJECT 2000 0 0 0 0 0 | |
dry/types/definition.rb:59 T_OBJECT 2000 0 0 0 0 0 | |
dry/struct/class_interface.rb:77 T_OBJECT 2000 0 0 0 0 0 | |
dry/types/constrained.rb:20 T_DATA 4000 0 0 0 0 0 | |
dry/types/constrained.rb:27 T_ARRAY 4000 0 0 0 0 0 | |
dry/logic/rule.rb:47 T_ARRAY 4000 0 0 0 0 0 | |
dry/logic/rule.rb:47 T_DATA 4000 0 0 0 0 0 | |
dry/types/definition.rb:51 T_ARRAY 4000 0 0 0 0 0 | |
dry/types/hash/schema.rb:92 T_ARRAY 6000 0 0 0 0 0 | |
dry/struct.rb:16 T_STRING 6000 0 0 0 0 0 | |
{:total=>47010} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment