Improve BSON handling of string keys and values

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON, Performance
    • None
    • None
    • Python Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      While working on PYTHON-5965, I found a performance win that affects the existing
      bson. I measured about a 15% improvement on a spawn perf host on the standard bson tests.

      {write_unicode}} (string values) and decode_and_write_pair (string keys) allocate a temporary bytes per element using PyUnicode_AsUTF8String.

      Definition of done

      • Switch to PyUnicode_AsUTF8AndSize, which returns a borrowed pointer into the string's cached UTF-8 buffer with no temporary allocation.

      Pitfalls

      The pointer is borrowed, so keep the source string alive until after the buffer write (else use-after-free)

            Assignee:
            Unassigned
            Reporter:
            Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: