Giter Club home page Giter Club logo

django-compiling-loader's Introduction

Django-compiling-loader

A template loader that compiles Django templates into Python bytecode for improved performance.

https://api.travis-ci.org/mhallin/django-compiling-loader.svg?branch=master https://coveralls.io/repos/mhallin/django-compiling-loader/badge.svg?branch=master&service=github

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

django-compiling-loader's People

Contributors

mhallin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.