﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35332	Bad performance in django.template.load.render_to_string	Zeyad Moustafa	nobody	"Hi folks, thanks for your great job here.

So with the rise of rust we are seeing, I told myself to make a component of Django components in rust so we can get a better performance as memory safety and all of these features from rust.

While searching I discovered a great package called mini-jinja. so I just wanted to compare its performance with the Django template engine performance to figure out if what I am doing is good for the community or not. so here is the code I have written to know about the performance.


{{{
# mini-jinja.py
from minijinja import Environment


with open('test.html', 'r') as file:
    template = file.read()


env = Environment(
    templates={
        'test': template
    }
)

result = env.render_template('test', nums=range(1000000))

}}}

and this is the result of the testing.

{{{
❯ time python mini-jinja.py
python mini-jinja.py  1.27s user 0.03s system 99% cpu 1.302 total

dummy/python-tests/copper via 🐍 v3.10.12 (.venv)
❯ time python mini-jinja.py
python mini-jinja.py  1.23s user 0.03s system 99% cpu 1.259 total
}}}


and this is how I tested it in django
first created main.py file with this contents


{{{
import time
from django.template.loader import render_to_string


def render():
    start = time.time()
    _template = render_to_string(""test.html"", {""nums"": range(1000000)})
    end = time.time()
    print(end - start)
}}}

and then I opened the django shell and imported the main file and then typed render and here is what I got


{{{
❯ python manage.py shell
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type ""help"", ""copyright"", ""credits"" or ""license"" for more information.
(InteractiveConsole)
>>> import main
>>> main.render()
28.39499545097351
>>>
}}}
and here is the test.html I was using for both the tests

{{{
{% for num in nums%}

<h1>{{num}}</h1>

{% endfor %}
}}}

So here is my question. why a big difference between both of them?? is there anything I have done wrong or this is related to the nature of python?? I just opened this issue to know if it will be really good for the Django community to create a template engine using rust built on top of Mini-jinja or if there is something I have to modify in my tests to get the real result??"	Cleanup/optimization	closed	Template system	5.0	Normal	needsinfo	performance templates jinja		Unreviewed	0	0	0	0	0	0
