[Django] #36729: Pre-compile regular expressions as standard

1 view
Skip to first unread message

Django

unread,
4:30 AM (17 hours ago) 4:30 AM
to django-...@googlegroups.com
#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.

Django

unread,
11:20 AM (10 hours ago) 11:20 AM
to django-...@googlegroups.com
#36729: Pre-compile regular expressions as standard
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: Jake
Type: | Howard
Cleanup/optimization | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Unreviewed => Accepted

Comment:

Thank you Jake, I think this makes sense. Looking forward to your work!

Slightly related to #30899.
--
Ticket URL: <https://code.djangoproject.com/ticket/36729#comment:1>
Reply all
Reply to author
Forward
0 new messages