You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For my current project, I often need to extract data from various mongoengine documents into various dictionaries. I'm finding that there is a very large overhead when doing this, compared with normal objects. I'll illustrate with an example:
That's more than 200x slower and we're not even making calls to the database beyond the initial connection.
Obviously I expect some overhead but not this amount. Is there something I'm missing or a way I can quickly speed this up? It's worth noting that I'm only trying to extract data here, not modify it, so if there's a way to cast the document to a normal object or disable validation or something that may be useful.
I ran a quick profile of the script and the top 50 methods by total time are:
I've updated the benchmark a bit and here are my comparative results pre- and post-optimization; a clear improvement! (Apologies for how ugly the code in there is…)
For my current project, I often need to extract data from various mongoengine documents into various dictionaries. I'm finding that there is a very large overhead when doing this, compared with normal objects. I'll illustrate with an example:
I have the following 3 documents:
and I run the following script:
Output:
If I redefine the documents as normal objects:
and run the same script, the output is:
That's more than 200x slower and we're not even making calls to the database beyond the initial connection.
Obviously I expect some overhead but not this amount. Is there something I'm missing or a way I can quickly speed this up? It's worth noting that I'm only trying to extract data here, not modify it, so if there's a way to cast the document to a normal object or disable validation or something that may be useful.
I ran a quick profile of the script and the top 50 methods by total time are:
I'm using mongoengine version
0.13.0
Let me know if you need any more details!
The text was updated successfully, but these errors were encountered: