Active record is taking 7+ seconds to save one item! I'm using
activerecord not in rails.  I have a object that inherits
ActiveRecord::Base mapped to a table in mysql with 5 string columns and
3 text columns (and auto-generated id/time columns).  One column is a
serialized hash, but I made it an empty hash in all of the tests I ran.

I have this piece of code:

start = Time.now.to_i
entity.save
puts "Saving one item took #{Time.now.to_i-start} seconds"

... it outputs

Saving one item took 7 seconds.

The text in one of the text columns is code (quite a bit of C/C++ code),
and so I thought maybe all that escaping of fancy characters was slowing
things down.  I tried setting each string/text field to a single
character ("a","b","c"...) and the saves still took 6-7 seconds.

Doing the same database insertion with:

ActiveRecord::Base.connection.execute

tends to run in <1 second.  Unfortunately this means I have to make sure
to escape/serialize all my own data, thus rewriting code and potentially
introducing new bugs.  This is not an app that requires speed per-se,
but it does need to commit about 10,000 of these entries once a week,
and at 7-8 seconds per that would take 22 hours, which is not
acceptable.

Does anyone have any ideas why this would be going so insanely slow?  I
am happy to provide further information (platform etc), but since the
insertions are fast when running ActiveRecord::Base.connection.execute,
I think this must be something I don't understand about activerecord
itself.
-- 
Posted via http://www.ruby-forum.com/.