python / python/mypy

Re-work how fine grained targets are processed

Open
#5,507 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs discussion performance priority-1-normal refactoring topic-fine-grained-incremental
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Currently, fine grained targets are processed per updated module. This can lead to files being processed multiple times (and also a bit hard to reason, but this may be subjective). I propose to reorganise them to be processed in topologically sorted order. So the algorithm would be like this:

  1. Process all edited files, calculate all fired triggers, chain them to find all invalid targets, check for blocking errors.
  2. Group targets per module, order them per SCC, then per same heuristics we use to order modules within SCCs in coarse grained incremental. Within module targets are ordered by line number, this is unchanged.
  3. Process targets in one module from the queue, calculate updated deps and fired triggers, update invalid targets queue (maintaining the sort order), check blockers
  4. Continue step 3 until no modules left in the queue at this SCC
  5. Flush error messages
  6. Continue steps 3-5 until no SCCs left

This way it is much less likely that we will reprocess the same module twice. This will probably give an especially significant performance gain for cold runs, where many modules are updated w.r.t. to remote cache. Also IMO this algorithm is easier to reason about (and more similar to what happens in coarse-grained mode).

This idea appeared some time ago, but was postponed. Filing an issue to not forget about this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing fine-grained incremental processing and the coarse-grained module-ordering logic. Compare the current per-updated-module flow with the proposed SCC-ordered target queue, including blocker checks and error flushing. Done means targets are processed in the stated order without unnecessary module reprocessing, with performance and behavior validated.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.