ObjectId class definition should use __slots__

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Major - P3
    • 1.10
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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 Hackett
            Reporter:
            unbeknownst
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: