Skip to content

ci: non-vacuous coverage-smoke corpus + a criterion noise floor (task #94, refs #17) - #19

Merged
DrunkOnJava merged 3 commits into
mainfrom
ci/canonical-corpus-and-bench-floor
Aug 30, 2026
Merged

DrunkOnJava merged 3 commits into
mainfrom
ci/canonical-corpus-and-bench-floor

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Aug 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

Two CI-gate-hygiene fixes: the coverage-smoke job now has a corpus to run against instead of skipping, and the Criterion job stops failing on runner noise. Task #94 and issue #17.


1. Coverage smoke test: a real corpus (task #94)

tests/fixtures/canonical/ held no .dwg file, so "Coverage smoke test (canonical corpus)" skipped with a warning on every run — a gate that could never fail.

The corpus README said this was blocked on write-path Stages 2-5. It is not. file_writer::assemble_dwg_bytes lands a complete R2004-family byte buffer, handle_map::write_handle_map emits AcDb:Handles, and the ElementEncoder impls cover LINE / CIRCLE / ARC / POINT. Wiring those together with a common-entity-preamble writer — the exact inverse of common_entity::read_common_entity_data — produces files this crate's reader decodes end-to-end.

What the corpus contains

examples/build_fixtures.rs (new) emits four files, one per version assemble_dwg_bytes accepts, 1216 bytes each. Each carries AcDb:Header (64-byte placeholder), AcDb:Handles, and AcDb:AcDbObjects with five entities: a 2D LINE, a 3D LINE with non-default thickness and extrusion, a CIRCLE, an ARC, and a POINT.

Measured — cargo run --release --example coverage_report -- tests/fixtures/canonical:

file                             version        deco   skip    err  ratio%
--------------------------------------------------------------------------------
synthetic_2004.dwg               AC1018 (2004)      5      0      0   100.0
synthetic_2010.dwg               AC1024 (2010)      5      0      0   100.0
synthetic_2013.dwg               AC1027 (2013)      5      0      0   100.0
synthetic_2018.dwg               AC1032 (2018)      5      0      0   100.0
--------------------------------------------------------------------------------
TOTAL                                             20      0      0   100.0

Generation is byte-deterministic; re-running the generator leaves git status clean.

The floor

Measured 100.0 %, floor set to 95.0 % — the measured value minus one entity out of twenty. The margin is deliberately that small and the workflow says so: decoded_ratio is a deterministic function of the committed bytes, not a timing measurement, so there is no CI noise to absorb. It exists only so a deliberately-unhandled fixture object (a DICTIONARY, to exercise the Unhandled path) can be added later without editing the workflow in the same commit.

CI changes

  • An empty corpus is now a hard failure, not a skip.
  • A new step regenerates the corpus and git diff --exit-codes it, so committed fixtures can never drift from the generator.
  • tests/canonical_corpus.rs (new) is the tight companion gate under cargo test: it pins per-file entity counts and decoded field values, so a bit-alignment regression that still "decodes" into garbage coordinates fails there even when the ratio would stay at 100 %.

Licence

Apache-2.0. No byte of any Autodesk-, ODA-, or third-party-produced DWG is redistributed — the files are generated by code in this repository. Provenance, command line, and base commit are recorded in tests/fixtures/canonical/README.md, along with the honest-scope note that these prove our reader round-trips our writer and nothing about AutoCAD acceptance.


2. Criterion noise floor (Refs #17)

The premise in #17 does not hold

#17 attributes the moved cell to "the longest-match path of the encoder — the most branch-predictor / alignment sensitive one".

lz77_encode::compress is literal-only. It emits one initial literal plus a terminator and performs no match search at all. The four bench cells are not a compressibility axis; they differ only in size.

An attribution probe — replace both compute_checksum call sites in build_section with black_box(0u32), re-run the bench — shows where the time actually is:

cell with checksums without checksum share
alt_1k 1.71 µs 0.23 µs 86 %
uniform_16k 21.25 µs 1.73 µs 92 %
mixed_64k 104.6 µs 8.27 µs 92 %
mixed_256k 333.7 µs 19.9 µs 94 %

So the cell is section_writer::compute_checksum — sum = rot1(sum) + b, a strict loop-carried dependency of two 1-cycle ops. 2 cycles/byte is the floor, and vectorisation is impossible (rot1 is 2x mod 2^32-1, the add is mod 2^32; they do not distribute). Measured ~2.2 cycles/byte, already within ~11 % of that floor.

The layout hypothesis, tested and rejected

Six measurements of uniform_16k on an M2 Max, taking the minimum per-iteration time across criterion's 100 samples rather than the mean (the minimum is the sample closest to running uncontended):

build unperturbed + unrelated pub fn added to bitwriter.rs
rolled checksum (main) 20802 ns / 21893 ns 20960 ns
8-way unrolled + #[inline(never)] 21830 ns 20867 ns

Everything lands in a 20.80–21.89 µs band with no consistent ordering by build. The same source measured twice moves 5.2 %. The perturbed builds came out faster in both rows. The unrolled + #[inline(never)] variant was therefore dropped from this PR: it stabilises nothing and it is not faster.

What was actually unstable: the estimator

On a loaded machine, criterion's mean reported 21.25 µs → 32.99 µs (+55 %) for a binary whose minimum-of-the-same-samples showed +4.9 %. mixed_256k in that run: mean +63 %, minimum +1.5 %.

A 21 µs benchmark on a shared GitHub vCPU cannot support a 20 %-ratio verdict on its own. That matches #13's run exactly: uniform_16k "regressed" 24 % while three sibling cells improved 10-17 % — a whole-group swing in both directions is the signature of runner noise, not of a code change.

The gate

Ratio threshold stays 1.20. A bench now fails only when all three hold:

  1. ratio = pr_mean / main_mean >= 1.20
  2. delta = pr_mean - main_mean >= 5000 ns
  3. the same bench trips (1) and (2) again on an immediate re-run

The table prints on every run regardless of verdict. The re-run only executes on the failing path, so the happy path costs nothing.

Why 5 µs: the cells it exempts (alt_1k ~1.7 µs, uniform_16k ~21 µs) exercise the same WriterScaffold::build_sections code path as mixed_64k (~100 µs) and mixed_256k (~334 µs), which stay gated because 20 % of them is 20–67 µs. No code path loses coverage; what the floor removes is the class of failure whose only evidence is a few microseconds on the smallest cell.

All of this reasoning, plus the jq recipe for extracting the minimum from sample.json, is in the header comment of .github/workflows/perf.yml.

Also in this half

  • .github/scripts/criterion-gate.sh reads criterion's own estimates.json with jq instead of scraping critcmp's formatted text. Drops cargo install critcmp (~1 min) from every run, removes a column-position parse that would silently mis-attribute if critcmp's layout changed, and gives the gate the exact nanosecond delta it needs. Exit 0 / 1 / 2 paths all exercised locally.
  • benches/write_path.rs switches to iter_batched, so the per-iteration 16–256 KiB payload clone is setup rather than measurement — it was charging allocator variance to the work under test. uniform_16k measures 19.85 µs after the change vs a 20.80–21.89 µs band before.
  • compute_checksum grows a doc comment recording the attribution numbers and the 2-cycles/byte floor, plus a test pinning its output at every length 0..300 × four seeds against the spec §4.6.1 reference definition — so the next person to try unrolling it has to stay byte-identical.

Refs #17 rather than Closes: item (3) of the issue is fixed, item (1) is answered with measurements, and item (2) is answered in the negative — there is no layout effect left to pin once the estimator is corrected. Closing is the maintainer's call.


Spec reference

Test plan

  • cargo fmt --all -- --check passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • cargo test --release --all-features passes (650 lib + 4 new canonical-corpus + all integration suites)
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features passes
  • cargo deny check all passes (advisories ok, bans ok, licenses ok, sources ok)
  • MSRV: CARGO_TARGET_DIR=target-msrv cargo +1.85.0 test --no-run --all-features passes
  • New code covered: tests/canonical_corpus.rs (4 tests) + checksum_matches_reference_definition_at_every_length
  • Corpus determinism verified by SHA-256 across regenerations
  • criterion-gate.sh exercised locally on all three exit paths (clean, tripped, cold-baseline)
  • Coverage-report numbers attached

Source-provenance declaration

Certified. No Autodesk DWG SDK source, no ODA Teigha / Drawings SDK source, and no GPL-licensed DWG implementation source (LibreDWG etc.) was consulted or imported. The write-path field orders used by examples/build_fixtures.rs were derived from this repository's own reader (common_entity::read_common_entity_data, object::ObjectWalker::read_one_at_pos, entities::*::decode) plus the ODA public Open Design Specification for .dwg files v5.4.1. No third-party source was read for this change.

Developer Certificate of Origin

Certified — DCO 1.1.


Note

Low Risk
Changes are mostly CI scripts, benchmarks, and test fixtures; production decode/write logic is documented and regression-tested rather than behaviorally altered.

Overview
Makes coverage-smoke a real gate and hardens perf CI against GitHub runner noise.

Coverage (task #94): Adds examples/build_fixtures.rs and committed synthetic DWGs under tests/fixtures/canonical/. The job fails if the corpus is missing, diff-checks fixtures against the generator, and raises the coverage_report floor from 20% → 95%. tests/canonical_corpus.rs pins per-file counts, geometry, and section/handle readability so ratio-only checks cannot miss bit-alignment garbage.

Perf (refs #17): Drops critcmp in favor of criterion-gate.sh (estimates.json + jq) and run-benches.sh. A regression requires ≥1.20× ratio, ≥5000 ns delta, and the same benchmark tripping on an immediate re-run. write_path uses iter_batched so payload clones are not timed; compute_checksum gets attribution docs and a byte-identical reference test. .gitignore adds /target-msrv/.

Reviewed by Cursor Bugbot for commit 1413a31. Configure here.

…age-smoke non-vacuous

tests/fixtures/canonical/ held no .dwg file, so the CI job "Coverage
smoke test (canonical corpus)" skipped with a warning on every run and
provided zero regression protection (task #94).

The corpus README said this was blocked on write-path Stages 2-5. It is
not: file_writer::assemble_dwg_bytes lands a complete R2004-family byte
buffer, handle_map::write_handle_map emits AcDb:Handles, and the
ElementEncoder impls cover LINE / CIRCLE / ARC / POINT. Wiring those
together with a common-entity-preamble writer (the exact inverse of
common_entity::read_common_entity_data) produces files this crate's
reader decodes end-to-end.

- examples/build_fixtures.rs generates the corpus: four Apache-2.0,
  self-generated files (~1.2 KB each), one per version
  assemble_dwg_bytes accepts (R2004, R2010, R2013, R2018), each with
  AcDb:Header + AcDb:Handles + AcDb:AcDbObjects and five entities
  (2D LINE, 3D LINE, CIRCLE, ARC, POINT). Generation is
  byte-deterministic.
- Measured with `cargo run --release --example coverage_report`:
  20 decoded / 0 unhandled / 0 errored, aggregate decoded_ratio 100.0%.
- ci.yml now fails when the corpus is empty instead of skipping, checks
  the committed bytes still match the generator, and asserts
  decoded_ratio >= 95.0 — the measured 100.0 minus one entity out of
  twenty. The margin is small on purpose: the ratio is a deterministic
  function of the committed bytes, not a timing measurement.
- tests/canonical_corpus.rs is the tight companion gate under
  `cargo test`: it pins per-file entity counts AND decoded field
  values, so a bit-alignment regression that still "decodes" into
  garbage coordinates fails even though the ratio would stay at 100%.

No byte of any Autodesk-, ODA-, or third-party-produced DWG is
redistributed; provenance and the honest-scope note are in
tests/fixtures/canonical/README.md.
…nfirming re-run

Refs #17.

Profiling first. An attribution probe (replace both compute_checksum
call sites in build_section with black_box(0u32), re-run the bench)
shows stage1_build_section/uniform_16k is 92% section_writer::
compute_checksum: 21.25 us -> 1.73 us. lz77_encode::compress is
literal-only and performs no match search at all, so #17's premise —
"the longest-match path of the encoder ... the most branch-predictor /
alignment sensitive one" — does not hold: the four bench cells differ
only in size, not in compressibility, and the moved cell is a serial
rotate-and-add chain, not a matcher.

That loop is `sum = rot1(sum) + b`, a strict loop-carried dependency of
two 1-cycle ops. 2 cycles/byte is the floor and vectorisation is
impossible (rot1 is 2x mod 2^32-1, the add is mod 2^32; they do not
distribute). Measured cost is ~2.2 cycles/byte, already within ~11% of
that floor.

Then the layout hypothesis, tested. Six measurements of
uniform_16k on an M2 Max, taking the minimum per-iteration time across
criterion's 100 samples rather than the mean:

  rolled checksum, unperturbed ................ 20802 ns / 21893 ns
  rolled checksum, + unrelated fn in bitwriter  20960 ns
  8-way unrolled + #[inline(never)], unperturbed 21830 ns
  8-way unrolled + #[inline(never)], + that fn  20867 ns

Everything lands in a 20.80-21.89 us band with no consistent ordering
by build. The same source measured twice moves 5.2%. The unrolled +
#[inline(never)] variant was therefore dropped: it stabilises nothing
and it is not faster.

What was actually unstable is the estimator. On a loaded machine
criterion's mean reported 21.25 us -> 32.99 us (+55%) for the same
binary where the minimum of the same samples showed +4.9%. A 21 us
bench on a shared GitHub vCPU cannot support a 20%-ratio verdict on its
own — which matches #13's run, where uniform_16k "regressed" 24% while
three sibling cells improved 10-17%.

So the fix is CI-side. A bench now fails only when all three hold:
  1. ratio  = pr_mean / main_mean >= 1.20 (threshold unchanged)
  2. delta  = pr_mean - main_mean >= 5000 ns
  3. the same bench trips (1) and (2) again on an immediate re-run
The table prints on every run regardless of the verdict, and the
re-run only executes on the failing path.

5 us is chosen so the cells it exempts (alt_1k ~1.7 us, uniform_16k
~21 us) exercise the same build_sections code path as mixed_64k
(~100 us) and mixed_256k (~334 us), which stay gated — no code path
loses coverage.

Also:
- .github/scripts/criterion-gate.sh reads criterion's own
  estimates.json with jq instead of scraping critcmp's formatted text,
  which drops a ~1-minute `cargo install` from every run and gives the
  gate the exact nanosecond delta it needs.
- benches/write_path.rs switches to iter_batched so the per-iteration
  16-256 KiB payload clone is setup rather than measurement; it was
  charging allocator variance to the work under test.
- compute_checksum grows a doc comment recording the attribution
  numbers, and a test pinning its output at every length and seed
  against the spec 4.6.1 reference definition, so the next person to
  try unrolling it has to stay byte-identical.
@cursor

cursor Bot commented Aug 30, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_0a77f808-f809-497d-b98b-be63a40d7f28)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant