Skip to content

Split large SCCs in parallel mode - #22541

Open
ilevkivskyi wants to merge 4 commits into
python:masterfrom
ilevkivskyi:split-sccs
Open

ilevkivskyi wants to merge 4 commits into
python:masterfrom
ilevkivskyi:split-sccs

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

This makes libraries like torch ~2x faster (tested with -n8), and self-check is up to 10% faster (again for -n8, with fewer workers gains are smaller).

Basic idea and technical side are quite straightforward. However, details of the sharding and scheduling logic are quite tricky. This is partially because I made a mistake when measuring interface vs implementation time: right now ~30-40% of time is spent in loading+interface. Most of it is spent in semantic analysis. This makes splitting semantic analysis into two phases imperative, if we want to see full gains from this PR.

Here are some important details of the PR.

First, we need to be sure that splitting will be effective, this means all of these must be true:

  • SCC must have large absolute size to compensate for extra communication overhead.
  • We should be able to split SCC into roughly equal shards.
  • SCC should not occupy more workers than needed (compared to other work ready in queue).

Second, we should split eagerly. It is quite common that a large bottleneck SCC arrives in the queue while there is only one free worker. The other will become free soon, so if we don't split, they all will be idling.

Third (the consequence of above), we should minimize interface penalty in case where we have split an SCC, but it was actually not needed. For example, if some other worker soon unblocked a big chunk of parallelizable work. For this purpose I introduce affinity for workers processing sharded SCCs. When a worker becomes free:

  • If it previously processed a shard of some SCC, we prioritize shards of this same SCC.
  • If it didn't process any of the currently sharded SCCs, we prioritize the other SCCs in queue.
  • Only if queue is empty we schedule shards on unfamiliar workers.

Note I also did some refactoring in worker code, since serve() function grew too large. I didn't do much parameter tuning. I think we should merge this PR, then try splitting the semantic analysis, and then I will do some parameter tuning.

cc @JukkaL

@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. ✅

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.

1 participant