Issue #1233: Decision: a measured run that suggests where parallel work pays

Open and answer this issue on GitHub.

tools, decision, future · opened 2026-11-04 · updated 2026-11-04 · 0 comments

The question

Should the toolchain get a command that runs a program once with light measurement and then suggests where parallel work would pay, for example nikaia profile? And should those suggestions stay suggestions, or may the compiler later apply them on its own?

This is not needed for the current focus. It is filed now so the reasoning is not lost, and labelled future.

Why it fits this language

Two questions decide whether a piece of work should run in parallel:

  1. May it? Does the work touch anything another part touches at the same time? The compiler can answer this reliably from what it already knows about each function: what it reads, what it writes, what it touches outside.
  2. Does it pay? Is the work heavy enough that handing it to another thread costs less than it saves? This cannot be known from the source. A loop over ten items and a loop over ten million look the same.

A compiler suggestion built on the first answer alone would be a guess, and a guess is not worth printing. A measured run supplies the second answer. A suggestion that rests on a proof and a measurement is reliable enough to show:

check.nika:212: this loop may run in parallel (proved) and took 38 % of the run, 4 ms per pass on average. With par_iter it would spread across the cores.

A loop that may run in parallel but takes microseconds is not mentioned at all.

How it would work

No interpreter is needed; it is a build option of the existing compiler.

What has to be watched

  1. The input must be representative. A run on a ten-line file says nothing about production load. The report always names the input it measured.
  2. Measurements go stale. When the code changes, the profile no longer fits. As a list of suggestions this is harmless: measure again.
  3. Reproducible builds. If the compiler applied a measurement on its own, the binary would depend on the measured run. That is only acceptable if the profile is a checked-in file that is part of the build input, as profile-guided optimisation works in C and Rust.

Options

A — no profiling tool. Parallel work stays the programmer’s call, found with an outside profiler. Cost: none. Weakness: the proof the compiler already has is never used to point at a place.

B — suggestions only. nikaia profile measures and prints suggestions; the programmer writes par_iter or async where they agree. What runs is always what is written. Cost: the instrumented build and the report. Weakness: the programmer must act on it.

C — suggestions, and later an optional checked-in profile. As B. In a later step a project may check in a profile file; the compiler then parallelises the places it proved independent and the profile measured heavy, without a change in the source. Cost: as B, plus the profile format and its place in the build. Weakness: what runs is no longer fully visible in the code; a stale profile can parallelise the wrong places (never an incorrect one, because the proof still decides what may run in parallel).

D — automatic, without a file. The compiler measures and applies on its own. Cost: builds that depend on a run. Not recommended.

Relation to #1232

The two complement each other:

The variant B5 in #1232 (hand a known-heavy call to the pool) needs to know which calls are heavy; a profile is one way to know.

First user: our own compiler

Our compiler is written in Nikaia and has a large, realistic input: the test programs, examples/ and lower-std. Today almost none of its Nikaia runs in parallel. A profiled run would show directly whether the prover’s obligations, the check per function or the emit per function are worth parallelising, and how much of a build is spent in our code against rustc. Before that, a plain measurement as docs/measuring.md says (counted instructions, per phase) answers part of the question without any new tool.

The checker currently threads one mutable context (errors, caches, counters) through every function; that context, not a missing annotation, is what keeps it sequential. A suggestion there would have to say so, not just “add par_iter”.

Recommendation

B now, C as a later step once B has shown its suggestions are right. D not at all.

What a decision changes

No build work starts before the owner decides and the version that carries it is chosen.


Generated by Claude Code

Back to Open Issues