[Grok-dev] z3c.relationfield slows down site dramatically

jmichiel jmichiel at yahoo.com
Thu Mar 7 15:07:19 UTC 2013


Hi, 

I'm using z3c.relationfield in my Grok site, and I had some specific
operations run surprisingly slow.
After profiling, I found out that it was updateRelations from
z3c.relationfield.event that was called unnecessary frequently.
After some further digging, I found the problem, and a possible solution:
The objects I'm using relationfields on are actually containers, containing
(in some cases lots of) small objects.
updateRelations  is called for each IObjectModifiedEvent on any object
providing IHasOutgoingRelations. Adding an object to a container will raise
a IContainerModifiedEvent, which is derived from IObjectModifiedEvent. So
each time I add an object to a container that uses relationfields,
updateRelations  is called, which turns out to be quite an expensive
operation.

However, adding/removing objects from a container will normally not (in my
case at least) change the container's relations, so this is unneeded
overhead. I tried by adding this at the start of updateRelations:


In my site everything seems to keep running OK (and signifficantly faster,
too).

Is this optimization too optimistic, though?

Regards,
Jeroen



--
View this message in context: http://python.6.n6.nabble.com/z3c-relationfield-slows-down-site-dramatically-tp5009190.html
Sent from the Grok mailing list archive at Nabble.com.


More information about the Grok-dev mailing list