Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-9267

Issues with readonly BSON in v8

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.2, 2.5.0
    • Affects Version/s: None
    • Component/s: JavaScript
    • None
    • ALL

      Read-only objects don't cache the converted v8 values and reconvert every time a field is accessed. This causes the following two major issues:

      1. this.x != this.x if x is an Object
      2. Since arrays are not lazy we need to build the entire thing each time we access. This is ok if the array is assigned to a variable then accessed through it but causes O(n^2) performance when accessed through a readonly object.

      Example:

      function mapFast() { // O(n)
          var array = this.array;
          for (var i=0; i<array.length; i++)
              emit(null, array[i]);
      }
      function mapSlow() { // O(n^2)
          for (var i=0; i<this.array.length; i++)
              emit(null, this.array[i]);
      }
      

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: