Opened 5 years ago
Closed 5 years ago
#30899 closed Cleanup/optimization (fixed)
Lazily compile regular expressions.
Reported by: | Adam Johnson | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | me@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Inspired by [this article from Instagram](https://instagram-engineering.com/python-at-scale-strict-modules-c0bb9245c834)
Currently Django lazily compiles some regular expressions such as those in validators: https://github.com/django/django/blob/54ea290e5bbd19d87bd8dba807738eeeaf01a362/django/core/validators.py#L17
This is to save on import time.
There are other import-time re.compile
calls throughout the codebase, these could be migrated to lazy regex compiles to save on their import time:
https://github.com/django/django/search?q=re.compile&unscoped_q=re.compile
Change History (8)
comment:1 by , 5 years ago
Summary: | Lazily compile large regular expressions → Lazily compile regular expressions. |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 5 years ago
Yeah django.utils.text sounds like a sensible location to me. Keeping it private (starting with underscore, undocumented) for now seems wise.
comment:5 by , 5 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I can work on this an prepare a patch.
Should I move the _lazy_re_compile function to django.utils.text?