Skip to content

mongoengine slow serialization of embedded documents with reference fields #1367

Open
@spitzbubchen

Description

@spitzbubchen

I have a small DB with about 500 records. Using the following model:

class Structure(db.EmbeddedDocument):
    form = db.ReferenceField(Form, required = True)

    @property
    def short(self):    
        return {
             'form': self.form
        }

class Record(db.Document):
    form = db.ReferenceField(Form, required = True)
    structure = db.EmbeddedDocumentField(Structure)

    @property
    def short(self):    
        return {
            'form': self.form # Takes about 1s
            # 'structure': self.structure.short # Takes about 25s
        }

And performing:

start = time.clock()
records = Record.objects.select_related()
print ('Time: ', time.clock() - start)  
response = [i.short for i in records]
print ('Time: ', time.clock() - start)

I'm finding that the query and serialization time for 'form': self.form.short case takes 1.12s and 1.36s, respectively, however, for the 'structure': self.structure.short case it is 1.14s and 24.1s. The query times have not changed, however, the serialization time for an embedded document with a reference takes about 24 times longer...! Why such a big difference? I've also submitted this as a stackoverflow question in case someone wants some points. http://stackoverflow.com/questions/39088519/mongoengine-slow-serialization-of-embedded-documents-with-reference-fields

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions