Expected Behavior
Jinja2 should import near-instantly
Actual Behavior
It imports in almost 250 milliseconds
Repro Code
import time
start = time.time()
import jinja2
end = time.time()
print('Jinja2 took ', end-start, 's to import')
Output: Jinja2 took 0.2398972511291504 s to import
The profiler shows that (in the profiled run), 289 ms was spent in _make_name_re in lexer.py.
Upon further inspection, I found that this line:
name_re = re.compile(r'[%s][%s]*' % (_stringdefs.xid_start,
_stringdefs.xid_continue))
is the culprit, taking around 159 ms to run. It's incredibly slow because of the sheer length of the regex.
Your Environment
- Python version: 3.6.1
- Jinja version: 2.9.6 (found similarly slow results on a git checkout seconds before submitting this)
Expected Behavior
Jinja2 should import near-instantly
Actual Behavior
It imports in almost 250 milliseconds
Repro Code
Output:
Jinja2 took 0.2398972511291504 s to importThe profiler shows that (in the profiled run), 289 ms was spent in _make_name_re in lexer.py.
Upon further inspection, I found that this line:
is the culprit, taking around 159 ms to run. It's incredibly slow because of the sheer length of the regex.
Your Environment