Skip to content
Jukka Lehtosalo edited this page Mar 28, 2022 · 2 revisions

Mypy is compiled using mypyc to C extension modules. This means that using the stdlib cProfile or profile module isn't going to be effective, unless you use a non-compiled mypy -- and in this case the results may not be indicative of performance when using a compiled mypy.

py-spy is a profiling tool that works with compiled mypy (at least in Linux).

Use it like this to profile mypy (replace -c 'import os' with your command line arguments):

$ pip install py-spy
$ pip install mypy
$ py-spy record --native -f speedscope -o profile.dat -- mypy -c 'import os'

Now open https://www.speedscope.app/, click Browse and import the profile.dat file you generated above. You can click 'Sandwich' to get a flat profile.

If the mypy run is relatively quick (less than a few seconds), consider using -r 500 with py-spy to increase the sampling rate.

Note: To get repeatable results, disable incremental mode by using mypy --no-incremental, or delete the .mypy_cache directory before each run.

If you are reporting a mypy performance issue or regression, feel free to add a link to the collected profile.dat (after you've verified with speedscope that it contains useful information) so that mypy developers can also analyze the profile.

Clone this wiki locally
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy