We have a fairly large django codebase with many URL routes. We found that for example when calling reverse, the resolver’s _populate function takes several seconds and causes latency for our users.
We wanted to simply cache this and have implemented a warm-start where we load in the URL resolver.
The problem is that it seems Django populates a URL resolver for each language, so even if we warm up the resolver for the default language, every language will experience a slow request on each serving thread.
Here are options as I see them:
remove all use of reverse in our application, and construct urls manually where needed
turn off the I18N setting so the default language is always used. (I do not think we can do this as we use translations, just never in our URL routes)
warm up URL resolver for every language we support in our warmup function.
come up with some way of doing language-agnostic URL resolving?
has anyone else encountered performance issues with reverse?
I’ve got a project with more than 1500 total urls defined, a little more than a third (568) are programmatically created by the Django admin - and _populate completes in less than 0.1 seconds.
How have you determined that it’s actually the _populate method causing issues?
here’s an example profile. and we have URLs in the thousands, although i’m not quite sure how many. it is an open source codebase, here our our main URL Conf files.