Issue #2926: The bounds prover spends 28 G Ir on a 70-line function over five parallel lists

Open and answer this issue on GitHub.

ready · opened 2026-11-29 · updated 2026-11-29 · 0 comments

The bounds prover spends about 28 G Ir on one 70-line function that indexes five parallel lists with the same counters. This issue makes that shape cheap, with every decision unchanged.

Found while handling the red perf gate of the ci lane (check.drive +51.77 %, re-recorded in the same push).

Today

drive_slow_lines in scripts/drive.nika (added in f11506984, the driver’s warning for slow CI jobs) fills five lists (runs, names, spans, starts, ends) in one loop, then reads them in nested while loops over i, j, n and m up to runs.len() or a count taken from it. With the same binary (target/fast at 11997d42b), nikaia check --bounds scripts/drive.nika costs about 44 % more with this function than without it. The prover’s own counts, from the work gate, are the same walks (4 896 against 4 727) and 2 072 more asks.

Probe: the function alone, with the use lines of drive.nika and fn main() {}, is below.

That is about 15 M Ir per ask. A cause is not settled.

To build

  1. Find out why with callgrind (--tree=caller on lg_contradictory_at): which asks are expensive, how many facts each ask carries, and whether the same question is asked again (compare the cache of the bounds-prover-asks-the-same-question issue, #2885).
  2. Make the expensive part cheaper without changing any answer. Candidates, to be confirmed by step 1: facts that do not touch the goal’s variables are dropped before the LIA search, or the search reuses work between asks.
  3. Add a tests/compiler/tests/ program with the probe’s shape whose .stdout stays the same.
  4. Re-record check.drive in benches/perf.baseline from the CI run, as its own commit.

Done when

use std::cli
use std::env
use std::fs
use std::io
use std::path
use std::process
use std::text
fn drive_slow_lines(lines: String) -> String throws {
	let mut runs: Vec[String] = []
	let mut names: Vec[String] = []
	let mut spans: Vec[i64] = []
	let mut starts: Vec[i64] = []
	let mut ends: Vec[i64] = []
	for raw in lines.split("\n") {
		let cells: Vec[String] = raw.trim().split(" ").collect()
		if cells.len() < 4 { continue }
		let start = text::parse_i64(cells[1].clone()) ?? continue
		let end = text::parse_i64(cells[2].clone()) ?? continue
		let mut name = cells[3].clone()
		let mut k: i64 = 4
		while k < cells.len() {
			name = name + "_" + cells[k]
			k += 1
		}
		runs.push(cells[0].clone())
		names.push(name)
		spans.push(end - start)
		starts.push(start)
		ends.push(end)
	}
	if runs.len() == 0 { return "" }
	// The whole of each run, as a job named `run`.
	let mut seen: Vec[String] = []
	let count = runs.len()
	let mut i: i64 = 0
	while i < count {
		let run = runs[i].clone()
		if !seen.contains(run.clone()) {
			seen.push(run.clone())
			let mut first = starts[i]
			let mut last = ends[i]
			let mut j = i
			while j < count {
				if runs[j] == run {
					if starts[j] < first { first = starts[j] }
					if ends[j] > last { last = ends[j] }
				}
				j += 1
			}
			runs.push(run)
			names.push("run")
			spans.push(last - first)
		}
		i += 1
	}
	let judged = runs[0].clone()
	let mut out: Vec[String] = []
	let mut slow: Vec[String] = []
	let mut n: i64 = 0
	while n < runs.len() {
		if runs[n] == judged {
			let mut before: Vec[i64] = []
			let mut m: i64 = 0
			while m < runs.len() {
				if runs[m] != judged && names[m] == names[n] { before.push(spans[m]) }
				m += 1
			}
			if before.len() >= 3 {
				let median = drive_median(before)
				let took = spans[n]
				if took > 2 * median && took - median >= 600 {
					let job = names[n].clone()
					out.push(f"SLOW {job} {drive_minutes(took)} min, median {drive_minutes(median)} min")
					slow.push(job)
				}
			}
		}
		n += 1
	}
	if slow.len() == 0 { return "" }
	out.push("Slow: " + slow.join(" "))
	return out.join("\n")
}
fn drive_median(mut spans: Vec[i64]) -> i64 {
	if spans.len() == 0 { return 0 }
	spans.sort()
	return spans[spans.len() / 2]
}
fn drive_minutes(seconds: i64) -> i64 {
	return (seconds + 30) / 60
}
fn main() {}

Back to Open Issues