
Performance degradation due to unnecessary inspect calls
Reported by Alexander Sorokin | October 26th, 2010 @ 01:44 PM | in 1.1
We're trying to upgrade to DM 1.0.2 from 0.10. We observed 3x performance hit for the new Datamapper. The performance degradation affected both specs (total time to run) and the running system (response time).
Upon investigation, I found that there are too many calls to "inspect" methods. I traced them down to Query.assert_valid_fields (ln 797). That inspect call isn't necessary unless there are errors. I also found the following unnecessary calls:
lib/dm-core/query.rb
792: inspect = field.inspect
821: inspect = inspect = link.inspect
849: inspect = subject.inspect
936: inspect = order_entry.inspect
lib/dm-core/associations/many_to_one.rb
158: collection = source.collection
I don't think this is a complete list
After fixing these particular instances, I was able to get from 3x time down to 2x time compared to DM 0.10.
Comments and changes to this ticket
-
Piotr Solnica (solnic) October 27th, 2010 @ 04:30 AM
- State changed from new to confirmed
- Milestone set to 1.1
- Assigned user set to Piotr Solnica (solnic)
- Milestone order changed from 196302 to 0
Nice catch!
-
Piotr Solnica (solnic) October 27th, 2010 @ 05:05 PM
Hmmm in case of datamapper specs the difference is small. The specs run about ~8 seconds faster.
-
Alexander Sorokin October 27th, 2010 @ 06:10 PM
The difference is quite significant on our codebase. We have a bunch of models with relationships and I was doing SomeMode.create 100 times. This amplified the performance loss.
Also, have you done profiling on the code? When done side by side, DM 1.0.2 calls many methods way more often than DM 0.10.0. I don't know the cause for that yet :(
-
Piotr Solnica (solnic) October 28th, 2010 @ 09:37 AM
Can you grab sources from http://github.com/solnic/dm-core/tree/performance and see if that really improves performance in your case?
-
Piotr Solnica (solnic) October 29th, 2010 @ 08:40 AM
- State changed from confirmed to resolved
(from [d972ae93a1bf08c9ac95d587eb6e4e875758dcff]) Performance improvements in query and associations
[#1438 state:resolved] http://github.com/datamapper/dm-core/commit/d972ae93a1bf08c9ac95d58...
-
Alexander Sorokin November 1st, 2010 @ 10:45 PM
This fix worked for me. It took the timing down to about 7-7.5 sec v.s. 4 sec on 0.10.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Referenced by
-
1438 Performance degradation due to unnecessary inspect calls [#1438 state:resolved] http://github.com/datamapper/dm-c...