mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Surprisingly long CI (github-actions) mypy execution time

Open piotr-rarus opened this issue 3 years ago • 2 comments

Hey folks, I guess this is a wrong place to post it, though at this point I kinda feel helpless and I won't get any substantial insights on StackOverflow. What's the story then? I've started working on some kaggle project with a friend using a fresh repo. We use mypy in our CI build pipeline. At some point github actions started reporting really long execution times on mypy step. Running mypy locally takes barely seconds as it's still very small repo. Let me show you one of them:

image

mypy takes almost 2 minutes for just a few files in a repo. Setting up python 3.10 takes considerable time, but it's mostly recovering poetry cache with some heavy libraries. That's ok. At first I thought we might have some problems using --install-types flag but that's not a case. I went throught the CI history and found out that mypy execution time went up, once we added pytorch to the project's dependencies. I guess mypy is running some type resolution/discovery stuff for used dependencies. Is there any way to cache it in a remote CI setting to reduce the execution times?

repo: https://github.com/piotr-rarus/kaggle-rsna-breast-cancer build workflow: https://github.com/piotr-rarus/kaggle-rsna-breast-cancer/blob/main/.github/workflows/build.yml

  - name: Mypy
    run: |
      poetry run mypy --incremental --show-error-codes --pretty src

All relevant env info is stated in the repo's toml. Dependencies are managed using poetry and pinned down in poetry.lock: https://github.com/piotr-rarus/kaggle-rsna-breast-cancer/blob/main/pyproject.toml

By no means I expect to get a fix, that's not a bug. Some substantial insights into proper CI mypy usage would be most welcome :)

Take care, you're my favourite python's lib.

piotr-rarus avatar Jan 09 '23 17:01 piotr-rarus

Hello! You could attempt to use https://github.com/actions/cache for caching the mypy cache in Github Actions CI. The next version of mypy has some nice performance improvements too, so hopefully that will help :-)

hauntsaninja avatar Jan 09 '23 20:01 hauntsaninja

I see .mypy_cache directory cover both external dependencies and my own code as well. Would it be save to cache it in CI setting? Does mypy do some internal tracking to know when to rebuild cache for each of the packages? How should I rebuild the cache? I could set hash key for poetry.lock but that would rebuild .mypy_cache even if single dependency changes. Tracking code changes also kinda defeats the purpose, if I'd have to rebuild the .mypy_cache on every single commit.

piotr-rarus avatar Jan 09 '23 21:01 piotr-rarus

.mypy_cache does keep track of things independent of each other - it's used for caching on your own dev machine! The only warning I have is that there are some cache-specific bugs, but those are treated like any other bug here (in that they're fixed if possible).

Hopefully this doesn't come off as necro-posting!

A5rocks avatar May 16 '23 23:05 A5rocks