Skip to content

Use parallel parsing at all stages#21266

Merged
ilevkivskyi merged 4 commits intopython:masterfrom
ilevkivskyi:parse-parallel-in-workers
Apr 20, 2026
Merged

Use parallel parsing at all stages#21266
ilevkivskyi merged 4 commits intopython:masterfrom
ilevkivskyi:parse-parallel-in-workers

Conversation

@ilevkivskyi
Copy link
Copy Markdown
Member

@ilevkivskyi ilevkivskyi commented Apr 18, 2026

This is a follow-up to #21175 and #21119.

Right now we are only using parallel parsing during initial graph loading. This PR allows using it when processing SCCs that are stale due to dependencies (these are not parsed on initial loading). Implementation is a bit less trivial than I thought, because we need to completely extract the tree de-serialization (which is not parallelizeable). It is still relatively straightforward. The new logic is like this:

  • When calling parse(eager=False) (default) we always return a serialized tree.
  • When calling parse(eager=True) a caller can force immediate de-serialization (when suitable), this will trigger load_from_raw().
  • To get more manual control (e.g. for imports_only=True) one can use parse(eager=False) followed by load_from_raw() directly.

cc @JukkaL

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a potential perf issue.

Comment thread mypy/build_worker/worker.py Outdated
needs_parse.append(state)
# Set data that is needed to be written to cache meta.
state.known_suppressed_deps_opts = suppressed_deps_opts
# Performa actual parsing in parallel (but we don't need to compute dependencies).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: performa

Comment thread mypy/build.py Outdated
for state in parallel_states:
assert state.tree is not None
if state.id in parallel_parsed_states:
if state in parallel_parsed_states:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O(n) contains check. Previously this was a dict so it used to be O(1). This loop is now O(n**2).

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@ilevkivskyi ilevkivskyi merged commit 15f1287 into python:master Apr 20, 2026
24 checks passed
@ilevkivskyi ilevkivskyi deleted the parse-parallel-in-workers branch April 20, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants