Rendering is very inefficient when USE_L10N. Caching format values gives 2-7 times improvement
|Reported by:||Teemu Kurppa||Owned by:||Jannis Leidel|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||no|
Django's rendering is really inefficient if localization is turned on (USE_L10N = True).
I have a spreadsheet like view with a few thousand numbers, dates and related data and it spend almost all of it's time in template rendering even when I preprocessed data carefully.
I investigated the issue and it seems that Django's localization implementation is doing a lot of unnecessary work for every rendered number, date and time.
Following patch introduces caching of locale-specific format values.
Speed improvements are considerable. On my laptop and our server, this gives 5-7 times improvement (from ~5 sec to <1sec) to rendering speed of an anomalistic view with 10000 integers. For my real-world spreadsheet view, the whole processing time of Django improves 2-3 times (from ~2sec to ~0.8sec)
In addition to the patch, I've included a test project, which can be used to test observe and test the problem.
Run test to see raw rendering performance
python manage.py test numbersperf
And to test it with server try
python manage.py runserver
And then visit these urls to observe and profile the problem
http://localhost:8000/test/10000 http://localhost:8000/test/10000?timing http://localhost:8000/test/10000?prof
Change History (27)
comment:2 Changed 7 years ago by
|Owner:||changed from anonymous to Teemu Kurppa|
|Status:||assigned → new|
comment:3 Changed 7 years ago by
|Owner:||changed from Teemu Kurppa to Jannis Leidel|
|Status:||new → assigned|
|Triage Stage:||Unreviewed → Accepted|