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 33700 APPEND_SLASH adds significant latency to all requests not ending in / (even if successful) Anders Kaseorg Anders Kaseorg "Originally, `APPEND_SLASH` worked by looking for 404 responses and replacing them with redirects, so as not to unnecessarily impact the performance of successful responses. However, commit 9390da7fb6e251eaa9a785692f987296cb14523f in 1.9.5/1.10 changed this to check `should_redirect_with_slash()` on every request, resulting in a moderately expensive extra `urlconf` lookup for every request not ending with `/`, whether or not it succeeds as written. This performance impact was not considered in the commit message or the corresponding ticket #26293, so I assume it was an oversight. That ticket asserted “This doesn't really make sense, since the two settings are not interdependent”, which is incorrect—performance was the reason for the interdependence. The overhead was found to be significant enough in Zulip to merit [https://github.com/zulip/zulip/commit/229090a3a58de15eb2a76a8e513fa5d9a190170c subclassing] `CommonMiddleware` to skip it in certain conditions. Here’s a [https://gist.github.com/andersk/0140318d32f1657ff40cad9e7e353bd2 minimal test project] with an exaggerated number of routes so the overhead can be easily observed. {{{ $ ./manage.py runserver }}} {{{ $ wrk http://127.0.0.1:8000/url9999 Running 10s test @ http://127.0.0.1:8000/url9999 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 232.40ms 73.85ms 570.86ms 69.16% Req/Sec 21.70 9.47 40.00 63.35% 426 requests in 10.01s, 64.90KB read Requests/sec: 42.56 Transfer/sec: 6.48KB $ sed -i 's/# APPEND_SLASH = False/APPEND_SLASH = False/' slash_test_settings.py $ wrk http://127.0.0.1:8000/url9999 Running 10s test @ http://127.0.0.1:8000/url9999 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 139.80ms 52.07ms 352.19ms 69.09% Req/Sec 36.46 12.23 60.00 58.12% 714 requests in 10.01s, 108.79KB read Requests/sec: 71.32 Transfer/sec: 10.87KB }}}" Cleanup/optimization closed HTTP handling 4.0 Normal fixed CommonMiddleware Sam Emett Speer Keryn Knight Florian Apolloner Ready for checkin 1 0 0 0 0 0