-
Notifications
You must be signed in to change notification settings - Fork 1.2k
INTPYTHON-617 - Improve DictField to_python performance #2888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Does your benchmark still apply? You seem to have changed the code substantially, and I would assume that the |
What do you by mean "still apply"? The benchmarking script was run against the current master branch as of June with and then without the change to |
return ( | ||
{k: to_python(v) for k, v in value.items()} | ||
if to_python and value | ||
else value or None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would convert a {}
to None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class MyModel(db.Document):
data_dict_1 = db.DictField(required=False)
m = MyModel()
m.data_dict_1 = {}
m.save()
model = MyModel.objects.first()
print(model.data_dict_1)
Outputs {}
.
I wrote what I meant right after
It's not obvious what commit you ran your benchmarking from, so I was just confirming. The rest of my comment applies. Have you profiled this to see what code is the bottleneck that you're removing? |
I was curious and had a quick look yesterday but I'm suspecting that it's only working with simple dicts (with native types that don't need any parsing), we must double check that it's also working with nested reference fields or embedded docs or fields that would require conversion when loaded from db. If you look at the basecomplexfield.to_python it has some code related with that that the current proposal is just skipping |
Is passing the existing test suite sufficient to say that this change doesn't introduce any breaking changes? Or is there a specific example or test I could add to verify correct behavior beyond what already exists in the suite? |
Improves performance of large documents with nested
DictFields
by nearly 20x, addressing #1230.Modified benchmark script pulled from https://stackoverflow.com/questions/35257305/mongoengine-is-very-slow-on-large-documents-compared-to-native-pymongo-usage/:
Before:
After: