#25753: Cache formats retrieved from django settings in formats.get_format
--------------------------------------+--------------------
     Reporter:  jaap3                 |      Owner:  nobody
         Type:  Cleanup/optimization  |     Status:  new
    Component:  Utilities             |    Version:  master
     Severity:  Normal                |   Keywords:
 Triage Stage:  Unreviewed            |  Has patch:  1
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+--------------------
 If L10N is disabled `formats.get_format` always goes through django's
 settings module to get the requested format type. Accessing settings is
 fairly expensive, so I propose caching these values in the same way the
 values are already cached when L10N is enabled.

 {{{
 import timeit
 import django
 from django.conf import settings
 from django.utils.formats import get_format

 settings.configure()
 django.setup()

 print('%s' % timeit.repeat("get_format('DATETIME_INPUT_FORMATS')",
 setup='from __main__ import get_format'))
 }}}

 Before:

 `[4.791080316994339, 4.822412799010635, 4.568255095000495]`

 After:

 `[2.801479902002029, 2.874774623007397, 2.796864636009559]`

 The performance remains the same for when L10N is enabled (e.g. replace
 `settings.configure()` with `settings.configure(USE_L10N=True,
 LANGUAGE_CODE='nl')`)

--
Ticket URL: <https://code.djangoproject.com/ticket/25753>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.4a86afa80f08e17d687c53ee3b2248e3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to