This page is a stub. This page presently only has reusable snippets.

Software performance depends on many choices: language (like Rust versus Python), framework (like FastAPI versus Django), architecture (e.g. map-reduce), networking (e.g. batch requests), etc. Many choices are costly to change at a later date (e.g. full rewrite).


Use profiling to:

  • Identify slow dependencies, in case faster alternatives can be easily swapped in

  • Find major hotspots, like a loop that runs in exponential time instead of quadratic time

  • Find minor hotspots, if changing language, etc. is too costly

Once a hotspot is found, the solution might be to:


For example:

cat packages.json | python -m cProfile -o ocdskit/ compile > /dev/null
gprof2dot -f pstats | dot -Tpng -o output.png
open output.png

To see where a running program is spending its time, use py-spy top.


For example:

pip install memory_profiler matplotlib
time mprof run libcoveoc4ids data.json
mprof plot