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

to_bson getting called 6 times on a collection insert

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.18.0
    • Affects Version/s: 2.14.0
    • Component/s: BSON
    • Labels:
      None

      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. 

       

       

       

        

       

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

              Created:
              Updated:
              Resolved: