Extremely long request time with StaticFilesPanel
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_PANELSand commending outStaticFilesPanel: ~0.030 s
Do you have additional details where the slowdown happens?
@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.
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 maybe if just disabling static file enumeration via configuration would solve the issue.