Skip to content

perf(engine): prepare each worker once and read summaries from a spool - #249

Merged
SizzleUnrlsd merged 1 commit into
mainfrom
perf/jobs-workers
Oct 13, 2026
Merged

SizzleUnrlsd merged 1 commit into
mainfrom
perf/jobs-workers

Conversation

@SizzleUnrlsd

Copy link
Copy Markdown
Contributor

Profile

mitmproxy, -j 8, main: 501 components, each one a task.

Phase Time
Preparing the project per task: plugins, dependencies, advisories, models 49 s of CPU
Decoding the transitive summaries each task received 32 s of CPU
Parent encoding and submitting those summaries, sequentially 32 s of wall time
Analysis itself 58 s of CPU

364 MB of summaries were shipped in total.

Change

  • Each worker prepares the project once, through the pool's initializer (_Project, _start_worker).
  • A task carries only its paths and, for each imported module, its import name and spool key.
  • The parent stores finished modules in a spool after each wave: the --cache directory, or a temporary directory of the run, removed at the end. Each worker reads an entry at most once.
  • A missing entry raises instead of analysing with missing summaries.
  • encode_index and decode_index, now unused, are removed.
  • The -j 1 path is unchanged.

Measurements

macOS, 8 cores (4 performance, 4 efficiency), Python 3.14, bundled plugins, cold start, low load. Reports are identical in every mode.

Project -j 1 -j 8 on main -j 8 with this change User time of -j 8
healthchecks 15.3–15.5 s 15.6–15.9 s 7.9–9.2 s 52 s → 27 s
mitmproxy 51.6 s 68.5 s 45.6 s 178 s → 90 s

Runs under heavy external load point the same way (user time, -j 8: 286 s → 124 s).

What remains

mitmproxy gains little over -j 1. One 37-module import cycle is analysed by a single process, and each wave waits for its slowest component. docs/usage.md now says so, in place of the "saves a quarter" sentence, with the measured table.

Verification

  • tests/test_jobs_workers.py, new. One test checks that a worker instantiates the plugins once (it fails on main: 8 instantiations for 2 workers). Two tests check that summaries reach the modules of later waves, with and without --cache, with the same report as -j 1. No existing test changed.
  • Full suite green, apart from the local test_packaging metadata issue (fails on main too). ruff check and mypy clean.

@SizzleUnrlsd SizzleUnrlsd added the enhancement New feature or request label Oct 13, 2026
@SizzleUnrlsd SizzleUnrlsd self-assigned this Oct 13, 2026
@SizzleUnrlsd
SizzleUnrlsd merged commit 501030a into main Oct 13, 2026
10 checks passed
@SizzleUnrlsd
SizzleUnrlsd deleted the perf/jobs-workers branch October 13, 2026 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant