Cache default_fields per serializer instance for faster serialization #433

merged 1 commit into from Nov 20, 2012


None yet

4 participants



While using the very nice django rest framework to serialize several thousands objects, we noticed some slower performance than our previous serialization methods. Profiling this code showed that more time was being spent creating default fields than should be the case -- that method was being run for each model instance, when it only needed to run per serializer instance.

Investigating the code further found comments that inspired this change. Serializing about 2000 objects was taking around 1.5 seconds -- with this change, take less than 0.5 seconds.



Wow that's a great performance increase. Are there any implications that might occur by merging this, @tomchristie?


Yes, I noticed this too -- the default_fields was by far the most time intensive though, and I wanted to keep this diff small. I'll submit a separate diff for get_fields changes in the near future.

@tomchristie tomchristie merged commit 9b63ba3 into tomchristie:master Nov 20, 2012

1 check passed

Details default The Travis build passed

@irrelative That'd be greatly appreciated, thanks.
This seems like a pretty damn good start for now tho.



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment