Skip to content

v0.4.2

Choose a tag to compare

@MasonLyons MasonLyons released this 18 Oct 11:24
· 4 commits to main since this release

The |localtime, |utc and |timezone filters and humanize's |ordinal now render fast. Before this release they ran at about the same speed as stock Django. On the benchmark, {{ value|timezone:"…" }} is now 9.8x faster than stock, {{ value|localtime }} 5.2x and {{ n|ordinal }} 24x.

pip install -U django-rust-templates

Faster

  • Time zone filters: localtime, utc and timezone return Django's datetimeobject (a datetime subclass). Printing that value, or passing it on to |date/|time, used to fall back to Python's date formatting. These values now take the same native path as plain datetimes.
  • ordinal (django.contrib.humanize): Django looks up all ten suffix translations on every call. The native version looks up only the one it needs.

Output stays byte-identical to stock Django. Subclasses of datetimeobject, inputs to ordinal other than plain ints, and patched humanize module globals still run the Python code.