Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-257

Performance of a BsonArray creation and AddRange method when "values" is either T[], IList<T> or an ICollection

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.2
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible

      While profiling one of our applications, I encountered that BsonArray implementation was relatively suboptimal when it's initialized with a medium-large sized (100-1000 elements) arrays. So, I created a patch which supports reserving space in internal values array if the amount of elements is known beforehand (if IEnumerable<T> is also an ICollection), along with some iteration improvements for arrays and IList<T> implementations. In my test case this leads to around 40-50% improvement on array creation. I also applied the same improvements to relevant methods (Clone, DeepClone). While I recognized that attached patch is largely untested, I ask you to consider if these improvements are worth including, and either include the changes I propose, or invent some other scheme to improve the T[]->BsonArray conversion process.

        1. BsonArray.cs.patch
          7 kB
        2. BsonArray.cs-new.patch
          7 kB
        3. CSHARP-257.patch
          40 kB
        4. perftest.zip
          2 kB

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            onyxmaster Aristarkh Zagorodnikov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: