#35364: AdminEmailHandler wastes work when ADMINS isn’t set
------------------------------------------------+------------------------
               Reporter:  Adam Johnson          |          Owner:  (none)
                   Type:  Cleanup/optimization  |         Status:  new
              Component:  Error reporting       |        Version:  dev
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  0
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 `AdminEmailHandler.emit()` does a lot of work to assemble the message it
 passes to `mail_admins`. If `settings.ADMINS` is empty, `mail_admins()`
 returns instantly, wasting all the message-creation work. It’s quite
 common to not configure `ADMINS`, whether in lieu of more advanced tools
 like Sentry, or during tests.

 In a quick benchmark on my M1 Mac Pro on Python 3.11, the overhead is
 ~2.5ms:

 {{{
 In [1]: import logging

 In [2]: logger = logging.getLogger('django')

 In [3]: %timeit logger.error("Yada")
 ...
 2.78 ms ± 75.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

 In [4]: logger = logging.getLogger('example')

 In [5]: %timeit logger.error("Yada")
 ...
 8.37 µs ± 38.9 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops
 each)
 }}}

 This can be avoided by adding an initial check to
 `AdminEmailHandler.emit()`.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35364>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018ec3149aae-5bb7be16-fce4-4747-871f-319944643c4c-000000%40eu-central-1.amazonses.com.

Reply via email to