MongoEngine / MongoEngine/mongoengine
Document instantiation performance
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
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"?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Start by profiling Document instantiation and reviewing the metaclass and initialization paths implicated by the report, using the supplied timeit comparison as a baseline. Done would require an agreed optimization or opt-out mechanism, plus evidence that instantiation is faster without changing persistence behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- database, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100