Fix is_dict_class detection to use the fast decode path

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • None
    • None
    • Python Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Summary:
      Fix is_dict_class detection to use the fast decode path. This is performance gap, not a correctness bug.

      Description:

      Context

      is_dict_class is computed with Py_IS_TYPE(options->document_class, &PyDict_Type). document_class is a class (a type object), and Py_IS_TYPE(x, T) is Py_TYPE == T. So we are comparing{{Py_TYPE(&PyDict_Type) == &PyDict_Type}}, which is false (it is PyType_Type). So is_dict_class was always false, forcing every document decode through the generic PyObject_SetItem path instead of the fast PyDict_SetItem path, adding object churn.

      Definition of done

      • Compute is_dict_class with an identity comparison: options->document_class == (PyObject*)&PyDict_Type.
      • test_bson.py and test_bson_corpus.py pass.

      Pitfalls

      • document_class is a class, not an instance, so Py_IS_TYPE is the wrong check; use identity equality.

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

              Created:
              Updated: