Skip to content

Commit

Permalink
Speed up integer casting from DB
Browse files Browse the repository at this point in the history
We don't have the check the range when the value is coming from the DB,
so override type_cast_from_database to short-circuit the extra work.
The difference is huge but the absolute gain is quite small. That being
said this is a hotspot and it showed up on the radar when benchmarking
discourse.
  • Loading branch information
sgrif committed Nov 18, 2014
1 parent 1b9e85d commit 52fddcc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activerecord/lib/active_record/type/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def type

alias type_cast_for_database type_cast

def type_cast_from_database(value)
return if value.nil?
value.to_i
end

protected

attr_reader :range
Expand Down

0 comments on commit 52fddcc

Please sign in to comment.