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.
Cache default fields per serializer instance for improved performance
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.
@irrelative That'd be greatly appreciated, thanks.
This seems like a pretty damn good start for now tho.