A template loader that compiles Django templates into Python bytecode for improved performance.
This package exposes the compiling_loader.Loader template loader. This loader will compile the template syntax tree generated by Django into Python bytecode. If a tag can’t be generated, a fallback will be compiled, which just evaluates the template nodes. The fallback method means that this loader is compatible with the existing loaders, even if you have a lot of custom tags.
The compiler is modular and built around Python 3.4’s singledispatch function, meaning that it can easily be extended to support your own tags if you have expensive custom tags that would benefit from compilation.
The loader itself does not do any caching; it works together with Django’s built-in cached loader to avoid recompilation.
Usage
Install the django-compiling-loader Python package and set the TEMPLATE_LOADERS settings to the following value:
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', [
('compiling_loader.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
]),
)
If you have other loaders, put them inside the compiling_loader.Loader list to ensure that the generated templates get compiled.
Compatibility
The loader has been tested with Django 1.7, and requires Python 3.4. When it comes to rendering compatibility, this project contains a fair number of test cases that compare the render output from the standard Django template evaluation and this compiler. So far, no incompatibilities have been found.
Performace
The test_proj/run_benchmarks.py script renders a small inheritance based template a large number of times, as well as a large both inheritance and include based template a few times. Below are some comparisons:
Template |
Default |
Compiled |
Speedup |
|---|---|---|---|
Small |
0.21 ms |
0.10 ms |
2,1x |
Large |
125 ms |
42 ms |
3,0x |
Metadata
Release files for django-compiling-loader 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-compiling-loader-0.0.1.tar.gz | 10.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_compiling_loader-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.2 kB
Release files / django-compiling-loader-0.0.1.tar.gz
| Download URL | django-compiling-loader-0.0.1.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
141fac2ff24e0139876ccd5db918ceee9228632e96dbefed49c131081392abef
|
|
BLAKE2b-256 checksum How to use checksums |
ccebf10e26543caf2fbd571eec07a5aa6a78aa85f182a0687a4ad5ebce7ab1b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_compiling_loader-0.0.1-py3-none-any.whl
| Download URL | django_compiling_loader-0.0.1-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f55f5a47544edbe39b97e6a1d2681846abdbdb50d60531f2310935e20df948b5
|
|
BLAKE2b-256 checksum How to use checksums |
3cbab741f62817af66eca3ca14f01c3a267ec972470e12108507ae54f3c06528
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |