ExportXMLWordPrintableJSON

    • Type: Task
    • Resolution: Fix Not Needed
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Server Programmability
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      from: https://jira.mongodb.org/browse/SERVER-97413

      And here are a few ideas that don't directly improve safety, but may improve the performance to reduce the impact of the extra checking, potentially making more checking possible:

      Explore storing the element size and/or type in BSONElement.
      Whatever we do, we must ensure that on a 64-bit platform it doesn't become larger than 16 bytes, otherwise it won't be passed or returned in registers which negates any potential improvement here. I suspect that that means we can only put size or type in the element and I suspect that type will be better, but we should measure to be sure.
      We need to load the type in order to compute the size. And basically any usage of BSONElement will also check the type. This includes the methods that check that the type is as expected (which we want more of). If we put it in the element, it can get it from the registers without reloading through the pointer. Also it should be easier for the compiler to see that the BSONElement is unaliased/unmodified than the pointed-to buffer.
      Putting the size in the element avoids needing to recompute it again. It also would let things like valueStringData() avoid putting loading through the pointer when returning a StringData.
      Consider marking the pointers in BSONObj and BSONElement with restrict and/or attributes that inform the compiler that they are always non-null (since they point to static data rather than null when empty).
      _fieldNameSize should be either 1 higher or lower. Right now it is the size including the NUL byte. I think this is basically never what we want. When returning fieldNameStringData we need to subtract 1. And when computing the start address of value() we need to add add one more to account for the type. If we choose to add 1 (which I suspect is better), we should rename the member _valueOffset.
      Note: this ticket is only focused on spatial memory safety, ie not reading outside of the bounds of the bson object. Temporal memory safety, ie not accessing already freed memory through a BSON view, is a separate issue that will be tackled differently.

            Assignee:
            Unassigned
            Reporter:
            Gabriel Spil
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: