Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2480

to_bson getting called 6 times on a collection insert

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 2.14.0
    • 2.18.0
    • BSON
    • None

    Description

      I've noticed that performance of inserts for very big documents (in terms of number of objects in the document's tree) seemed to be very poor, and that the majority of the time was spent in the client.

      So I ran a quick test to see how many time the `to_bson` method gets called per insert, and the answer is 6, which frankly seems to be quite too many.

      This is my simple test:

      class A 
         def initialize 
            @a = [1, 2, 3] 
         end 
         def bson_type 
            @a.bson_type 
         end 
         def to_bson(*args) 
            puts "to_bson" 
            @a.to_bson(*args) 
         end 
      end
      MyCollection.collection.insert_one({ary: A.new})
      

      This is the output:

       

      to_bson 
      to_bson 
      to_bson 
      to_bson 
      to_bson 
      to_bson
      

       

      I see there already is this bug https://jira.mongodb.org/browse/RUBY-2335 that's supposed to handle one case of redundant serialization connected with compression. 

       

       

       

        

       

      Attachments

        Issue Links

          Activity

            People

              neil.shweky@mongodb.com Neil Shweky
              daniele@spiketrap.io Daniele Tessaro
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: