tomchristie/django-rest-framework — pull request #439 by irrelative (2012-11-21 07:28:06+00:00)
Title: Cache all fields per serializer instance

This takes my previous pull request of caching the default_fields, and caches all per Tom's feedback. Please note the changes to the pagination plugin -- this could affect code in the wild.

Using my highly scientific benchmarking, this change takes my serialization of around 2000 items from 0.5 seconds to 0.37 seconds.

Future idea and thought: in a basic configuration of django model serialization, fields aren't dynamically updated and the get_fields method is very much a classmethod, so the field extraction *could* be done at metaclass.__init__ time. This is probably overkill, but could set up fields at startup time, not serializer instantiation time. IMO this is too much magic, but tweaking performance does this sort of thing to you :-)