christianwgd / django-bootstrap-icons

A quick way to add Bootstrap Icons with Django template tags.
MIT License
24 stars 7 forks source link

Massive performance problems using {% bs_icon 'download' %} #34

Closed mirec75 closed 1 week ago

mirec75 commented 1 week ago

Yesterday I was long hours investigating an unpleasant performance problem in my Django "Hello World" web app. It turned up, that the problem was the usage of following icon in my HTML template in a for loop.: {% bs_icon 'download' %}

Performance problem: The page reload takes roundabout 4 seconds each time to just fetch the HTML page from the Django while rendering 10 times (I was using a for loop) the: {% bs_icon 'download' %} Without any {% bs_icon 'download' %} the page reload takes just about 10 milliseconds each time to just fetch the HTML page from the Django, so it is about 400 times faster!

Repro: just put this in a blank Django HTML template and let Django rendert it with some dummy view: {% load bootstrap_icons %} {% load static %}

{% bs_icon 'download' %} {% bs_icon 'download' %} {% bs_icon 'download' %} {% bs_icon 'download' %} {% bs_icon 'download' %} {% bs_icon 'download' %} {% bs_icon 'download' %} {% bs_icon 'download' %} {% bs_icon 'download' %} {% bs_icon 'download' %}

Explanation: the: {% bs_icon 'download' %} results all the time into a SVG markup embedded in the result HTML like this:

<?xml version="1.0" ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16">

    <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5"/>

    <path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/>

</svg>
christianwgd commented 1 week ago

Please check #32 first, I would suppose that it will solve your problem. If not, let me know. Thanks.

mirec75 commented 1 week ago

:) yes, thanks, the BS_ICONS_CACHE works like a charm for the performance problem. I suggest, you should put this information very prominent and with appropriate warnings in the installation instruction on all sites propagating this django-bootstrap-icons package, e.g. here:

Due to the missing hint about BS_ICONS_CACHE my colleague an I run blindly into this performance problem. As I look through the closed issues, we were not the only ones. I suggest, you shall throw an error if the BS_ICONS_CACHE is not provided, or use some default.

I can close the issue now, but perhaps it helps like a reminder for the documentation and / or the error throwing?