Skip to content

Commit

Permalink
per discussion remove instrumentation altogether
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Mar 14, 2013
1 parent 31ba6fb commit 08a182d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 34 deletions.
9 changes: 0 additions & 9 deletions bench/perf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,13 @@ def include_age?
u = User.new(1, "sam", 10, "about")
s = UserSerializer.new(u)

u2 = User.new(2, "sam", 20, "about")
s2 = UserSerializer.new(u2)

p s2.attributes

p s.attributes


n = 100000

Benchmark.bmbm {|x|
x.report("init") { n.times { UserSerializer.new(u) } }
x.report("fast_hash") { n.times { u.fast_hash } }
x.report("attributes") { n.times { UserSerializer.new(u).attributes } }
x.report("serializable_hash") { n.times { UserSerializer.new(u).serializable_hash } }
x.report("serializable_hash_with_instrumentation") { n.times { UserSerializer.new(u).serializable_hash_with_instrumentation } }
}


26 changes: 1 addition & 25 deletions lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,37 +284,13 @@ def as_json(options={})

# Returns a hash representation of the serializable
# object without the root.
def serializable_hash_without_instrumentation
def serializable_hash
return nil if @object.nil?
@node = attributes
include_associations! if _embed
@node
end


def serializable_hash_with_instrumentation
return nil if @object.nil?
instrument(:serialize, :serializer => self.class.name) do
@node = attributes
instrument :associations do
include_associations! if _embed
end
@node
end
end

# disable all instrumentation on serializable_hash (performance will be better)
def self.disable_instrumentation!
alias_method :serializable_hash, :serializable_hash_without_instrumentation
end

# enable instrumentation for serializable_hash (performance may be impacted)
def self.enable_instrumentation!
alias_method :serializable_hash, :serializable_hash_with_instrumentation
end

disable_instrumentation!

def include_associations!
_associations.each_key do |name|
include!(name) if include?(name)
Expand Down

0 comments on commit 08a182d

Please sign in to comment.