riak-ripple / ripple

A rich Ruby modeling layer for Riak, Basho's distributed database
Other
619 stars 152 forks source link

Performance Issue with Embedded Document #268

Closed yehudaz closed 12 years ago

yehudaz commented 12 years ago

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

seancribbs commented 12 years ago

@yehudaz I'm working on a fix for this, do you have a test case/script/example that I can use to verify it?

seancribbs commented 12 years ago

@yehudaz Actually, will you just see if this patch resolves the issue? https://gist.github.com/1817132