perf: time the execution path, not the opt-in Observation document
ci/woodpecker/push/main Pipeline was successful
ci/woodpecker/manual/performance Pipeline was successful

The first rc.3 perf comparison reused the old workload commands but switched
them to `run/call --output json`, so the candidate was timed while producing
thousands of structural events that the beta baseline never emitted. The result
was a reproducible +240..+375% p50 and +130% RSS delta caused by the
measurement, not by the program's execution cost.

- Give each run/call workload a correctness command (current Observation
  snapshot, full contract digest) and a measurement command (plain execution
  path, committed text digest).
- Verify the correctness digest once per workload and the measurement digest on
  every timed sample; a wrong or changed output is never timed.
- Re-record the expected digests and extend the tooling tests.
- A protocol document that is produced only on request must not be billed as
  an execution regression.
This commit is contained in:
cflmy committed 2026-11-24 22:25:30 +08:00
1 parent f211568c42
commit 1e2a045cc7
12 files changed
+223 -57

No files matched your search

+10 -6
View File
@@ -8,12 +8,16 @@ workload whose wire output did not match the committed expected digest.
* Build one release binary with `cargo build --release --locked -p marqdo-cli`
and keep it fixed for the whole run. The report records its SHA256, the
`Cargo.lock` digest, `rustc -vV`, source SHA and profile.
* Correctness comes first: every warmup run is parsed and hashed. A mismatch
is `CORRECTNESS_FAIL`; its faster wall time is never reported.
`run`/`call` workloads request the current Observation snapshot
(`--output json`); the digest pins the terminal status/result, the committed
stdout/stderr byte digests and the ordered event-kind counts, never a run id
or a host path, so it is stable across invocations.
* Correctness comes first. Each workload has one correctness command and one
measurement command. For `run`/`call` the correctness command requests the
current Observation snapshot (`--output json`) and its digest pins the
terminal status/result, the committed stdout/stderr byte digests and the
ordered event-kind counts; the measurement command is the same program
without the opt-in observability destination, and every timed sample must
reproduce the committed text digest. A mismatch is `CORRECTNESS_FAIL`; its
faster wall time is never reported. Comparing the timed execution path
against the baseline execution path is the point: an opt-in protocol document
must not be billed as a product regression.
* Approved-node release evidence needs at least 5 warmups and 20 samples per
workload on a dedicated, stable node. A maintainer-approved shared-node
RC comparison needs the same sample counts in at least three paired runs.
@@ -1,4 +1,9 @@
{
"measure_argv": [
"run",
"tests/conformance/semantics/55-first-fit-free-list-allocator.mq.md"
],
"measure_sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"normalized": {
"events": {
"by_kind": {
+5
View File
@@ -1,4 +1,9 @@
{
"measure_argv": [
"run",
"tests/conformance/semantics/63-memory-bytecode-vm.mq.md"
],
"measure_sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"normalized": {
"events": {
"by_kind": {
+8
View File
@@ -1,4 +1,12 @@
{
"measure_argv": [
"call",
"examples/factorial.mq.md",
"数学.阶乘",
"--arg",
"n=5"
],
"measure_sha256": "sha256:97b912eb4a61df5f806ca6239dde3e1a4f51ad20aced1642cbb83dc510a5fa6b",
"normalized": {
"events": {
"by_kind": {
+5
View File
@@ -1,4 +1,9 @@
{
"measure_argv": [
"run",
"tests/conformance/semantics/71-http-parser.mq.md"
],
"measure_sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"normalized": {
"events": {
"by_kind": {
+5
View File
@@ -1,4 +1,9 @@
{
"measure_argv": [
"run",
"tests/conformance/semantics/62-json-array-parser.mq.md"
],
"measure_sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"normalized": {
"events": {
"by_kind": {
+5
View File
@@ -1,4 +1,9 @@
{
"measure_argv": [
"run",
"tests/conformance/semantics/70-matrix-multiply.mq.md"
],
"measure_sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"normalized": {
"events": {
"by_kind": {
@@ -1,4 +1,9 @@
{
"measure_argv": [
"run",
"stdlib/demo.mq.md"
],
"measure_sha256": "sha256:4f5fcde6b4073511330c50f15bf07db13abc2cf0cf71de777e8e23ca870220fe",
"normalized": {
"events": {
"by_kind": {
+5
View File
@@ -1,4 +1,9 @@
{
"measure_argv": [
"run",
"tests/conformance/semantics/65-table-sort-stdlib.mq.md"
],
"measure_sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"normalized": {
"events": {
"by_kind": {
+114 -51
View File
@@ -159,28 +159,37 @@ def expected_path(name: str) -> Path:
return EXPECTED / f"{name}.json"
def load_expected(name: str) -> str | None:
def text_digest(data: bytes) -> str:
"""Digest of measured text output with the checkout path normalised."""
normalized = data.replace(str(ROOT).encode(), b"<repo>")
return f"sha256:{hashlib.sha256(normalized).hexdigest()}"
def load_expected(name: str) -> dict | None:
path = expected_path(name)
if not path.is_file():
return None
return json.loads(path.read_text())["wire_sha256"]
return json.loads(path.read_text())
def record_expected(name: str, document: dict) -> None:
def record_expected(
name: str,
document: dict,
measure_stdout: bytes | None,
measure_argv: list[str] | None,
) -> None:
EXPECTED.mkdir(parents=True, exist_ok=True)
payload = {
"schema": "marqdo.perf.expected.v1",
"workload": name,
"wire_sha256": wire_digest(document),
"normalized": normalize(document),
}
if measure_stdout is not None:
payload["measure_sha256"] = text_digest(measure_stdout)
payload["measure_argv"] = measure_argv
expected_path(name).write_text(
json.dumps(
{
"schema": "marqdo.perf.expected.v1",
"workload": name,
"wire_sha256": wire_digest(document),
"normalized": normalize(document),
},
ensure_ascii=False,
sort_keys=True,
indent=2,
)
+ "\n"
json.dumps(payload, ensure_ascii=False, sort_keys=True, indent=2) + "\n"
)
@@ -308,62 +317,116 @@ def run_workload(
prefix = []
if cpu_list:
prefix = [shutil.which("taskset") or "taskset", "-c", cpu_list]
argv = prefix + [str(binary)] + workload["argv"]
# Correctness and measurement are separate commands for run/call: the
# machine document (Observation snapshot) pins the full public contract,
# while timing copies the plain execution path so an opt-in observability
# contract is not compared against a summary document.
correctness_argv = prefix + [str(binary)] + workload["argv"]
measured_argv = prefix + [str(binary)] + (workload.get("measure_argv") or workload["argv"])
env = dict(os.environ)
env.pop("MARQDO_STDLIB_DIR", None)
if not (binary.parent / "stdlib" / "stdlib.json").is_file():
env["MARQDO_STDLIB_DIR"] = str(ROOT / "stdlib")
env.setdefault("NO_COLOR", "1")
expected = load_expected(name)
expected_document = load_expected(name)
expected = expected_document.get("wire_sha256") if expected_document else None
expected_measure = (
expected_document.get("measure_sha256") if expected_document else None
)
result = {
"name": name,
"kind": workload.get("kind", "run"),
"source": workload["source"],
"argv": workload["argv"],
}
if workload.get("measure_argv"):
result["measure_argv"] = workload["measure_argv"]
correctness = "VERIFIED"
warmup_samples: list[dict] = []
measured: list[dict] = []
# Correctness is checked on every warmup execution; a wrong result is never
# timed and can never become a "fast" regression sample.
for index in range(warmups + samples):
code, usage, wall, stdout, stderr = spawn_capture(
argv, ROOT, env, timeout
)
if code != 0:
correctness = "CORRECTNESS_FAIL"
result["error"] = (
f"exit {code}: {stderr.decode('utf-8', 'replace')[:500]}"
)
break
measure_stdout: bytes | None = None
# One correctness preflight per workload: the machine document must match
# the committed contract digest before anything is timed.
code, _usage, _wall, stdout, stderr = spawn_capture(
correctness_argv, ROOT, env, timeout
)
if code != 0:
correctness = "CORRECTNESS_FAIL"
result["error"] = f"exit {code}: {stderr.decode('utf-8', 'replace')[:500]}"
else:
try:
document = json.loads(stdout)
except json.JSONDecodeError as error:
correctness = "CORRECTNESS_FAIL"
result["error"] = f"invalid JSON: {error}"
break
digest = wire_digest(document)
if record:
record_expected(name, document)
expected = digest
if expected is None:
correctness = "UNVERIFIED_NO_EXPECTED"
elif digest != expected:
correctness = "CORRECTNESS_FAIL"
result["error"] = (
f"wire digest mismatch: expected {expected}, got {digest}"
document = None
if document is not None:
digest = wire_digest(document)
if workload.get("measure_argv"):
code, _usage, _wall, measure_stdout, stderr = spawn_capture(
measured_argv, ROOT, env, timeout
)
if code != 0:
correctness = "CORRECTNESS_FAIL"
result["error"] = (
f"measurement probe exit {code}: "
f"{stderr.decode('utf-8', 'replace')[:500]}"
)
document = None
if record and document is not None:
record_expected(
name, document, measure_stdout, workload.get("measure_argv")
)
expected = digest
if measure_stdout is not None:
expected_measure = text_digest(measure_stdout)
if document is not None:
if expected is None:
correctness = "UNVERIFIED_NO_EXPECTED"
elif digest != expected:
correctness = "CORRECTNESS_FAIL"
result["error"] = (
f"wire digest mismatch: expected {expected}, got {digest}"
)
elif measure_stdout is not None:
probe = text_digest(measure_stdout)
if expected_measure is None:
correctness = "UNVERIFIED_NO_EXPECTED"
elif probe != expected_measure:
correctness = "CORRECTNESS_FAIL"
result["error"] = (
"measurement output mismatch: expected "
f"{expected_measure}, got {probe}"
)
# Timing loop: only a verified workload contributes samples, and every
# sample's output must match the committed measurement digest.
if correctness == "VERIFIED":
for index in range(warmups + samples):
code, usage, wall, stdout, stderr = spawn_capture(
measured_argv, ROOT, env, timeout
)
break
sample = {
"wall_ms": wall * 1000.0,
"user_ms": usage["user_ms"],
"sys_ms": usage["sys_ms"],
"max_rss_kb": usage["max_rss_kb"],
}
if index < warmups:
warmup_samples.append(sample)
else:
measured.append(sample)
if code != 0:
correctness = "CORRECTNESS_FAIL"
result["error"] = (
f"exit {code}: {stderr.decode('utf-8', 'replace')[:500]}"
)
break
if expected_measure is not None and text_digest(stdout) != expected_measure:
correctness = "CORRECTNESS_FAIL"
result["error"] = "measurement output changed between samples"
break
sample = {
"wall_ms": wall * 1000.0,
"user_ms": usage["user_ms"],
"sys_ms": usage["sys_ms"],
"max_rss_kb": usage["max_rss_kb"],
}
if index < warmups:
warmup_samples.append(sample)
else:
measured.append(sample)
result["correctness"] = correctness
if correctness != "VERIFIED":
+35
View File
@@ -23,6 +23,13 @@
"n=5",
"--output",
"json"
],
"measure_argv": [
"call",
"examples/factorial.mq.md",
"数学.阶乘",
"--arg",
"n=5"
]
},
{
@@ -34,6 +41,10 @@
"tests/conformance/semantics/55-first-fit-free-list-allocator.mq.md",
"--output",
"json"
],
"measure_argv": [
"run",
"tests/conformance/semantics/55-first-fit-free-list-allocator.mq.md"
]
},
{
@@ -45,6 +56,10 @@
"tests/conformance/semantics/62-json-array-parser.mq.md",
"--output",
"json"
],
"measure_argv": [
"run",
"tests/conformance/semantics/62-json-array-parser.mq.md"
]
},
{
@@ -56,6 +71,10 @@
"tests/conformance/semantics/65-table-sort-stdlib.mq.md",
"--output",
"json"
],
"measure_argv": [
"run",
"tests/conformance/semantics/65-table-sort-stdlib.mq.md"
]
},
{
@@ -67,6 +86,10 @@
"tests/conformance/semantics/63-memory-bytecode-vm.mq.md",
"--output",
"json"
],
"measure_argv": [
"run",
"tests/conformance/semantics/63-memory-bytecode-vm.mq.md"
]
},
{
@@ -78,6 +101,10 @@
"tests/conformance/semantics/70-matrix-multiply.mq.md",
"--output",
"json"
],
"measure_argv": [
"run",
"tests/conformance/semantics/70-matrix-multiply.mq.md"
]
},
{
@@ -89,6 +116,10 @@
"tests/conformance/semantics/71-http-parser.mq.md",
"--output",
"json"
],
"measure_argv": [
"run",
"tests/conformance/semantics/71-http-parser.mq.md"
]
},
{
@@ -100,6 +131,10 @@
"stdlib/demo.mq.md",
"--output",
"json"
],
"measure_argv": [
"run",
"stdlib/demo.mq.md"
]
}
]