Hobo / hobo

The web app builder for Rails (moved from tablatom/hobo)
http://hobocentral.net
103 stars 39 forks source link

can_wrap_with_hobo_type? extension of ActiveRecord::Base is a performance problem #157

Closed stevemadere closed 9 years ago

stevemadere commented 9 years ago

Under typical circumstances, the method ActiveRecord::Base.can_wrap_with_hobo_type?(attr_name) gets called very often and it has a dismally slow technique for determining if an attribute can be wrapped. Namely, it tries calling attr_type(attr_name) and checks to see if that raises an error.

In rails, raising errors in the ordinary course of doing business is extremely costly since the stack traces that get created before the rescue are absolutely huge.

I propose memoizing this method since there are only a few distinct attributes but they may be accessed many, many times.

I will submit a PR straight away.