solnic / coercible

Powerful, flexible and configurable coercion library. And nothing more.
MIT License
137 stars 16 forks source link

Memory bloat in method_missing #28

Open Epigene opened 4 years ago

Epigene commented 4 years ago

Hi, we're using v1.0.0 (via Virtus v1.0.5), and running memory_profiler gem's report on a loop-intensive part of our code reports that coercible is allocating 90% of strings:

Allocated String Report
-----------------------------------
   2134952  "to_object"
   2134952  /bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/object.rb:164

    100361  "amd"
    100361  /bundle/ruby/2.5.0/gems/money-6.11.3/lib/money/currency.rb:39

     83296  ""
     38591  /bundle/ruby/2.5.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/mysql/database_statements.rb:37

Could freezing strings avoid this?