#36729: Pre-compile regular expressions as standard
-------------------------------------+-------------------------------------
Reporter: Jake | Owner: Jake Howard
Howard |
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: dev
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
See also [https://forum.djangoproject.com/t/rfc-pre-compiling-regular-
expressions-as-standard/43311 forum thread].
It's fairly well known that there's a performance boost pre-compiling
regexes (either using `re.compile` or `_lazy_re_compile`, depending on
popularity). However, some of Django's internals compile at time of use,
which adds unnecessary extra work. Python's `re` module caches the most
recent 512 patterns, however a reasonably sized Django project can easily
go beyond that.
I suggest replacing patterns defined at runtime with pre-compiled patterns
done at module import time (or `_lazy_re_compile` if the pattern isn't
used much). This probably wants to be done as a single patch, rather than
trying to separate per module or the ticket dragging on.
I also suggest reasonably rejecting any non pre-compiled regexes in the
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/coding-style/#python-style coding style].
--
Ticket URL: <https://code.djangoproject.com/ticket/36729>
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 view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019a77665d7a-dbb84274-62c5-4fdf-a0b8-1b3db5b68d70-000000%40eu-central-1.amazonses.com.