django-debug-toolbar icon indicating copy to clipboard operation
django-debug-toolbar copied to clipboard

Extremely long request time with StaticFilesPanel

Open pembo13 opened this issue 5 years ago • 4 comments

I just recently upgraded from django-debug-toolbar==2.2 to django-debug-toolbar==3.1.1. Unfortunately, I did this after a few changes to the core behaviour of the project in question, and so upon noticing a significant increase in response times, across all views I started taking apart changes to no available until I downgraded django-debug-toolbar and everything went back to normal.

Coming here, If found #1263, and proceeded to start testing the removal of panels, starting with an empty DEBUG_TOOLBAR_PANELS. Ultimately, I singled out debug_toolbar.panels.staticfiles.StaticFilesPanel

To quantify the problem, using response times as seen in Firefox's Network Tab for a HTML response:

  • with 2.2: ~0.030 s
  • with 3.3.1 (no settings.py changes): ~1.100 s
  • with 3.3.1 (declaring DEBUG_TOOLBAR_PANELS and commending out StaticFilesPanel: ~0.030 s

pembo13 avatar Oct 21 '20 05:10 pembo13

Do you have additional details where the slowdown happens?

matthiask avatar Oct 13 '24 13:10 matthiask

@matthiask I believe the source of of the slowdown is is get_staticfiles_finders(), accounting for over over 99% of the time of generate_stats():

num_found 0.00000
num_used 0.00005
staticfiles 0.00002
staticfiles_apps 0.00384
staticfiles_dirs 0.00005
staticfiles_finders 1.65044

It's enumerating every static file, used or not, in order to display "django.contrib.staticfiles.finders.FileSystemFinder (95449 files)" and list all these files in the result panel. I'm not sure how useful that is, but it's time consumption is likely proportional to the number of files.

pembo13 avatar Dec 09 '24 12:12 pembo13

Thanks! Yeah, that sounds right. Also, it will possibly be much worse if people are using a cloud-based static files storage.

I'm not sure enumerating all available static files is all that useful.

matthiask avatar Dec 09 '24 15:12 matthiask

@matthiask maybe if just disabling static file enumeration via configuration would solve the issue.

pembo13 avatar Dec 11 '24 04:12 pembo13