Skip to content

v0.2.0

Choose a tag to compare

@MasonLyons MasonLyons released this 17 Oct 19:28
· 28 commits to main since this release

Faster rendering for real pages: the slow paths that a page rendered the way a view does hits (backend + request, context processors, forms, i18n, aware datetimes, humanize) were mostly bridged Python. On the new end-to-end benchmark, benchmarks/realworld.py, the Rust engine went from 1.5x → 2.6x faster than stock Django.

pip install -U django-rust-templates

New

  • RustFormRenderer: Django's default FORM_RENDERER builds its own stock template engine, so form and widget HTML never went through RustTemplates. To render it natively too, set:

    FORM_RENDERER = "django_rust_templates.forms.RustFormRenderer"

    It uses the same templates and produces identical output, about 2.6x faster. The Django admin change form renders in 9.6 ms with it, vs 17.0 ms on stock.

Faster

  • Aware datetimes (USE_TZ=True, Django's default): timezone conversion is native, saving ~9 µs per value. Also speeds up {% now %}.
  • date / time filters: the 'c' format and locale-named formats (bare |date, SHORT_DATE_FORMAT, TIME_FORMAT) went from 1.3–1.6x to 8–13x.
  • {% translate "literal" %} is native (1.2x → 7.3x), and lazy translations (gettext_lazy labels and verbose names) render 4.5x faster.
  • striptags is native for ordinary HTML (1.4x → 28x). Anything unusual still uses Django's own strip_tags.
  • humanize intcomma on integers: 1.7x → 10.9x, with locale grouping and separators.
  • {% url %}: 6.8 → 4.4 µs.

Fixes

  • copy.deepcopy() of a native Engine now works. Before, deep-copying form.errors failed when forms rendered through RustTemplates.
  • The active language is no longer read stale after Django swaps out its translation state, which happens on settings changes and when the dev server's autoreloader reloads translation files.
  • Language lookups now follow Django's own trans_real / trans_null choice exactly.

Known gaps

  • The body of a bridged block tag ({% localtime %}, {% cache %}, third-party block tags) still renders at stock speed.
  • {% blocktranslate %}, {% static %} and humanize naturaltime are still Python.

Output stays byte-identical to stock Django. Django's template test suite passes 100% on 5.2 and 6.1, and Django's forms, admin, i18n, humanize and timezones test apps also pass when run through the Rust engine.

Full change: #1