seancribbs/ripple — Issue #268: Performance Issue with Embedded Document
Author: yehudaz
Created: 2012-01-18 13:45:55+00:00
State: open

Hi,

I have a script that runs over ~200,000 rows, creates an embedded document per row and adds each X embedded docs to a Document (5 embedded docs to a document by average). The script does other stuff as well.

At first, running the script took too long. Using profiler, I’ve noticed the adding takes the majority time: report << item.

After debugging the code of ‘<<’ function in ‘many_embedded_proxy.rb’, I’ve noticed that each call to “Array(docs)” causes a ‘missing_method’ call which activates ‘define_attribute_methods’ function.

I’ve tried to coat the embedded doc parameter myself before calling ‘<<’ and removed the following lines from the ‘<<’ function:

def <<(docs)
load_target
#@reflection.verify_type!(Array(docs), @owner)
#assign_references(docs)
#@target += Array(docs)
@target += docs # instead of the previous line
self
end

And my script ran 10 times faster. I thought that removing these lines will cause a problem to the ‘save’ method of the document, but the save went ok.

Am I missing something by removing these lines? Is there a problem with the code?

I'm working with riak 1.0.2 nad Ripple 1 Beta.

I've found a similar issue here - https://github.com/couchrest/couchrest_model/pull/26

Thanks,

Yehuda Zargarov