The root problem is that mongoengine switched from pymongo ensure_index to create_index method inside mongoengine ensure_indexes.
ensure_index had simple caching mechanizm but create_index doesn't have it.
This switch plus that ensure_indexes is called on each doc.save() results in that mongodb need to handle with createIndex which is quite heavy operation and in our case this results in 50% drop in performance.
ensure_index was added here #812 because there was problem with test and IMHO it was a workaround. Better solution could be to make proxy method drop_database similar to drop_collection which would reset cls._collection on Document.
Later I will prepare pull request with such change.
The root problem is that mongoengine switched from pymongo
ensure_indextocreate_indexmethod inside mongoengineensure_indexes.ensure_indexhad simple caching mechanizm butcreate_indexdoesn't have it.This switch plus that
ensure_indexesis called on eachdoc.save()results in that mongodb need to handle withcreateIndexwhich is quite heavy operation and in our case this results in 50% drop in performance.ensure_indexwas added here #812 because there was problem with test and IMHO it was a workaround. Better solution could be to make proxy methoddrop_databasesimilar todrop_collectionwhich would resetcls._collectionon Document.Later I will prepare pull request with such change.