Summary: The exception reports in Django use the pprint
to pretty print variables in the stack frame of the exception. The pprint
function uses a lot of memory and time to render the entire object and trim it to the desired length later. This becomes significant if the variable is of huge size.
I’m planning to prevent this by using the reprlib like the previous contributors to the ticket and finish it.
First I wanted to implement a kind of size check and leave the variables that are not oversized to pprint itself so that the experience is not altered much, but seems like there is no fast and accurate way to measure large variables’ memory in Python. It’s either inaccurate or becomes really slow to deeply evaluate a variable’s memory usage.
Thus, it’s best to completely switch to reprlib. We can to try add indentations and limits within the instance constructor so that we get our desired result.
I was planning to use ‘4096’ the current limit for all data types and indentation as 4.
Please post any feedback on the same.
Reference for reprlib configuration: