Django: profile memory usage with Memray
Summary
Memray is demonstrated as an effective tool to profile memory usage in Django apps, including profiling the check command and generating flame graphs for startup performance. A concrete example shows a startup memory hotspot caused by importing numpy and presents several strategies to reduce startup memory, such as deferring imports, lazy imports, or using a lighter alternative like random.shuffle. The article also provides practical tips for iterating with a Zsh one-liner to streamline testing.