Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-225

ObjectId class definition should use __slots__

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.10
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Adding a single line of code to the ObjectId class definition will save a significant amount of memory for application dealing with many instances of that class. In some of our benchmarks the memory working set was reduced by up to 40% when adding a _slots_ declaration.

      The code would look like this:

      class ObjectId(object):
      """A MongoDB ObjectId.
      """
      _slots_ = ('__id')

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            unbeknownst unbeknownst
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: