This project is archived and is in readonly mode.
Dramatic rendering slowdown from 3.0.3 to 3.0.6
-
Santiago Pastorino
- State changed from new to open
- Milestone set to 3.0.6
- Assigned user set to Santiago Pastorino
- Importance changed from to Low
Can you check if reverting this commit https://github.com/rails/rails/commit/86acbf1cc050c8fa8c74a10c735e4... fix your issue?
-
stiang
Indeed it does, Santiago, specifically the changes to activerecord/lib/active_record/attribute_methods/read.rb. Reverting those makes my app perform as it did with 3.0.3 (or even a little better, it seems).
-
stiang
I’ve investigated this a bit more and come to the conclusion that rescue is extremely expensive on ruby 1.8. When I run this gist I get the following results on my machine:
Showing results for 1000000 method calls Method IS NOT defined ===================== With rescue: 10.35 seconds With respond_to: 0.64 seconds Direct call: 0.35 seconds Method IS defined ================= With rescue: 0.57 seconds With respond_to: 0.85 seconds Direct call: 0.35 secondsUnless I’m misunderstanding something, it would appear that changing
def read_attribute(attr_name) send "_#{attr_name}" rescue NoMethodError _read_attribute attr_name endin read.rb to something like
def read_attribute(attr_name) if respond_to? "_#{attr_name}" send "_#{attr_name}" else _read_attribute attr_name end endshould improve the speed dramatically when the underscore method doesn’t exist, and only add a slight penalty (the respond_to call) when it does. Any thoughts?
-
stiang
I added a pull request for this change after verifying that the tests pass with it.
(Actually, this test failed, but that appears to be wholly unrelated to my change.)
-
Santiago Pastorino
- State changed from open to committed