python / python/mypy

How to properly use shared mypy cache with daemon mode

Abierto
#16,784 0 comentarios 8 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

documentation
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

I intend to implement a modified version of the suggestion here to streamline the mypy type checking process, focusing on running the mypy server to perform type checks without requiring users to handle complex daemon restarts or cache management. The primary goal is to optimize the startup time for dmypy, particularly on CI (currently taking 10 minutes) and locally (taking 3 minutes), which exceeds the desired duration.

I tried using a zipped version of the cache on CI and it dropped it to 7 minutes which is better.
Not the biggest difference, but I feel it adds up when you have many engineers working on a code base over a week.

Workflow I'm considering (Applicable to both CI and local branches of the developing engineer):

  1. Check for Zipped Cache Directory:

    • If a zipped cache directory exists, unzip it to create the mypy cache directory.
    • If it doesn't exist, Create the cache directory using mypy --cache-fine-grained (basically cold start)
  2. Run dmypy with Fine-Grained Cache:

    • Execute dmypy --cache-fine-grained to initiate the mypy server with fine-grained caching.

Additional Step (Only on the Local Branch):

  1. Pushing to Remote Branch:
    • When a user pushes changes to the remote version of the branch, zip the cached directory and push it.

Things I'm worried about:

  • Cache Conflicts: Given this shared nature of the mypy cache, I'm concerned about possible conflicts. If multiple developers are merging their branches into the main branch concurrently, there could be scenarios where changes from different branches conflict within the mypy cache. I'm uncertain about how the mypy cache handles such conflicts.

  • Race Conditions: I'm worried about potential race conditions during cache updates. If developers are pushing changes simultaneously, there might be situations where the mypy cache is being updated by multiple processes concurrently. Understanding how the cache handles such race conditions is crucial to ensure consistency.

  • Main Branch Activity: Considering the dynamic nature of a main branch with continuous merges throughout the day, I'm unsure about how well the mypy cache will cope. The frequent changes to the codebase might pose challenges in maintaining an accurate and up-to-date cache for type checking.

  • Stacked PRs: Stacked pull requests could introduce complexities, and I'm uncertain about the impact on the mypy cache. The overlapping changes in stacked PRs might lead to unexpected behavior or difficulties in managing the cache effectively.

These considerations arise from a lack of confidence in understanding the internal mechanisms of the mypy cache.
I'm seeking further clarification on how the mypy cache handles concurrent updates, conflicts, and rapid changes in a collaborative development environment.

Should I even be using a shared cache in CI or run a fresh cycle of MyPy ?

A bunch of these concerns stem from this comment in the docs.

If you use the mypy daemon, you may want to restart the daemon each time after the merge base or local branch has changed to avoid processing a potentially large number of changes in an incremental build, as this can be much slower than downloading cache data and restarting the daemon.

I think as a starter I'd really just love some documentation on the basics of the cache, what to expect, and what to do/ not do.

I'm unsure how MyPy will handle things if the cache is stale for example .

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la documentación enlazada de funciones adicionales de mypy y las indicaciones existentes sobre reiniciar dmypy después de cambios en merge-base o en las ramas. Documenta los conceptos básicos de la caché, el comportamiento de las cachés obsoletas, las actualizaciones simultáneas y si las cachés comprimidas compartidas son adecuadas para CI o para ramas locales. Se considera terminado cuando el flujo de trabajo esperado y los límites de la gestión de la caché estén claros para los usuarios.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
documentation
Tipo de issue
Documentación
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.