django-htmlmin icon indicating copy to clipboard operation
django-htmlmin copied to clipboard

Introducing the middleware makes everything slooooooooooow

Open intellectronica opened this issue 10 years ago • 9 comments

One of our heavier pages was taking a very long time to load and often timing out. Took ages to understand why this is happening in production and not in development, and eventually we realised that setting DEBUG to False is what makes things slower (unintuitively). Turns out the culprit was the htmlmin middleware.

Other than general optimization, one solution could be to bail out and serve the unminified input if minification hasn't completed within a certain timeout period.

intellectronica avatar Dec 11 '14 15:12 intellectronica

I had the same problem.

lucasmagnum-luizalabs avatar Apr 10 '15 18:04 lucasmagnum-luizalabs

What is the response size? What is the middleware order?

andrewsmedina avatar Apr 11 '15 03:04 andrewsmedina

I ran a test script on my machine.

ghost@amnesia ~/dev/django-htmlmin/htmlmin $ python speed.py 
0.0757081508636
0.0739748477936
ghost@amnesia ~/dev/django-htmlmin/htmlmin $ python3 speed.py 
0.08755087852478027
0.08422636985778809
ghost@amnesia ~/dev/django-htmlmin/htmlmin $

Since the can_minify_response is not using anything that the self provides, can we not move it outside the class? Or is that bad practice? Moving it outside will make it a tad bit faster. Should I create a Pull Request?

theSage21 avatar Jun 20 '15 13:06 theSage21

Same issue here. Has there been any fix lately?

MarkDoggen avatar Dec 21 '16 11:12 MarkDoggen

I also meet this performance issue

especially for large contents. The html compression cost more than network transfer.

before htmlmin

image

after htmlmin

the transfer size is down, however the response time is nearly doubled.
image

suqi avatar Jan 23 '17 03:01 suqi

Same issue here. The minification takes so long the response time is doubled or more.

Yobmod avatar Sep 01 '17 13:09 Yobmod

A workaround that improved things a bit for me was setting HTML_MIN_PARSER = 'lxml', as lxml parser is way faster than the one from html5lib used by default.

lockie avatar Oct 13 '17 09:10 lockie

I experienced the slow down as well, JMeter results showed nearly double response time which defeats the entire purpose of this package...

jordotech avatar Oct 14 '19 22:10 jordotech

I'm experiencing the same behavior. My cpu load triples when I enable django-htmlmin.

image

Using the lxml parser as suggedted by @lockie seems to slightly improve the situation but not much.

PabloCastellano avatar Oct 13 '20 11:10 PabloCastellano