Skip to content

Document instantiation performance #1137

Open
@kengruven

Description

@kengruven

This is probably a less common use case. I've got a mongoengine.Document that represents a common data structure in my application, which I store in my database, and it's great for that. But it's also a generally useful class, and in one place, we create it in an inner loop (to make use of its methods) without ever touching the database.

In this case, object instantiation can take up a non-trivial amount of time, especially compared to normal Python objects:

>>> timeit.timeit('Foo()', 'class Foo(object): pass', number=100000)
0.013084888458251953
>>> timeit.timeit('Bar()', 'import mongoengine\nclass Bar(mongoengine.Document): pass', number=100000)
2.403195858001709

Is there any way to make this more efficient? Or perhaps even to signal to mongoengine: "This is never going to be written to disk, so I don't really need all the metaclass stuff"?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions