Performance¶
Django management command startup time has the potential to be noticeably slow, especially for large
projects with many apps and models. Django must be fully bootstrapped before management commands can
run. This can make the CLI feel sluggish and presents particular challenges for shell completion as
this delay is incurred each time <tab> is pressed.
If you are experiencing difficulty with shell completion we recommend:
Enabling menu based completion navigation in your terminal. This can reduce the number of calls to
shellcompletion. For z-shell this would look like:zstyle ':completion:*' menu select
Use import and performance analysis tools to determine if there are import bottle necks that can be lazily loaded.
The following benchmarks show total module loads, import and runtimes. All times are in seconds.
The first benchmark is for a minimal project that uses the settings file generated by
startproject. You can see that when rich is installed several hundred extra
modules must be imported. This adds a few 10s of milliseconds to the import time. To avoid this,
uninstall rich. As of Typer 0.17, rich is lazily loaded, but until certain
improvements are made to Typer
, the import time penalty is still incurred by django-typer.
The second benchmark shows the same stats for the polls example code.
These benchmarks compare the BaseCommand native implementation
to the TyperCommand implementation. They show that the overhead of
using django-typer is minimal. On the order of a few 10s of milliseconds. Adding
rich increases this overhead slightly, but the impact is still barely noticeable.