Speed up processing of new files in daemon by caching ASTs (#10128)
Processing newly installed stub files, in particular, could be quite slow incrementally
in mypy daemon. This is because adding N files results in N steps interally, each of
which adds one file. However, each step parses all remaining files, resulting in
an O(n**2) algorithm.
For example, processing `six` stubs could take about 40s (when not using a
compiled mypy).
Partially address the issue by caching parsed ASTs during a single increment.
This speeds up the `import six` use case by about 3x when not using a compiled
mypy. It's still about 3x slower when using daemon, however.