Skip to content

feat(tables): R2007+ LTYPE / BLOCK_HEADER string-stream decoders, LWPOLYLINE DD vertices, R2013/R2018 boundary pins - #13

Merged
DrunkOnJava merged 3 commits into
mainfrom
wip/april-decoder-tables
Aug 30, 2026
Merged

DrunkOnJava merged 3 commits into
mainfrom
wip/april-decoder-tables

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Aug 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

Recovers ~1,400 lines of April 2026 decoder work that was left uncommitted in the reconnaissance checkout, re-gated on a clean clone: modern (R2007+) LTYPE and BLOCK_HEADER table paths that read names from the split string stream, LWPOLYLINE DD vertex decoding, LINE DD end coordinates, BitCursor::read_dd, real-DWG regression tests, and the re-measured coverage docs.

Motivation

Symbol-table names (block records, linetypes) and correct polyline vertices are exactly what Revit-exported DWGs are made of, and this is the step toward dwg-rs being usable as a documented-format oracle for rvt-rs geometry. Measured aggregate real-file coverage moves from 7.3% to 20.1% on the 19-file local sample set; the R2018 sample from 13.8% to 44.2%.

Changes

See the CHANGELOG entries this PR adds (dated 2026-04-29, #103): src/tables/{ltype,block_record}.rs, src/entities/{dispatch,line,lwpolyline}.rs, src/bitcursor.rs, src/bitwriter.rs, src/common_entity.rs, src/element_encoder.rs, tests (r2013_entity_values, integration_entity_regression, proptest_roundtrip), examples (two new trace probes), README / STATUS / ROADMAP / docs numbers.

Testing

  • cargo build --all-targets, cargo fmt --check, cargo clippy --all-targets --all-features -- -D warnings: clean
  • cargo test --all-targets: every suite green (649 lib tests + integration suites)
  • examples/coverage_report.rs re-run today against the same sample set reproduces the README table exactly: 458 decoded / 1,660 skipped / 163 errored / 20.1%; sample_AC1032.dwg 329 / 337 / 79 / 44.2%
  • Note: the original working tree and .git were archived byte-for-byte first (~/Developer/archive/dwg-rs-uncommitted-2026-08-30/); the recon checkout is untouched.

Note

Medium Risk
Large changes to bit-aligned entity and table decoders on production DWG payloads; regressions would misdecode geometry or names, though real-DWG tests and coverage metrics mitigate that.

Overview
This PR lands a batch of #103 real-file decoder fixes that realign R2013/R2018 payloads and recover more symbol-table strings on modern DWGs. Measured corpus decode success rises from ~7.3% to ~20.1% aggregate (AC1032 ~13.8% → ~44.2%), with README/ROADMAP/STATUS and announcement copy updated to match.

Bit primitives and geometry: Adds read_dd / write_dd and switches LINE end points from BD deltas to DD defaults (each start coordinate). LWPOLYLINE vertices use first-point RD/RD, then DD/DD chained from the previous vertex. common_entity preamble is corrected for traced R2013/R2018 data (drops obsolete modern layer/linetype bits, R2013+ DS-data bit, RC shadow_flags, R2004+ CMC suffix skips without eating handle-stream bits).

R2007+ tables: BLOCK_HEADER and simple LTYPE records get split string-stream decode paths in block_record / ltype, wired from dispatch with legacy inline fallback. Dump example prints BlockRecord and LTYPE names.

Verification: tests/r2013_entity_values is active (no #[ignore]) with assertions on line_2013.dwg, AC1032 LINE/LWPOLYLINE populations, and expected block/ltype names. New forensic examples trace_entity_boundary and trace_table_entry support boundary debugging.

Reviewed by Cursor Bugbot for commit d0e3a03. Configure here.

…OLYLINE DD vertices, R2013/R2018 boundary pins

Uncommitted April 2026 work recovered from the reconnaissance checkout
(~/Developer/re/dwg-recon-2026-04-19/tools/dwg-rs) and re-gated on the
clean clone: build, fmt, clippy -D warnings, and every test suite green
(649 lib tests). Content, as documented in the CHANGELOG entries it adds:

- LTYPE and BLOCK_HEADER modern paths read R2007+ table-record names from
  the split string stream (ODA v5.4.1 §19.1 / §19.5.3), with fallback to
  the legacy inline decoder when the modern parse is implausible
- LWPOLYLINE vertices as first point RD/RD then DD/DD against the previous
  point; LINE end coordinates as DD with the start as default
- BitCursor::read_dd and bit-writer counterparts
- real-DWG regressions in tests/r2013_entity_values.rs (block-record and
  linetype names on sample_AC1032.dwg, LINE geometry on line_2013.dwg,
  LWPOLYLINE bodies), two new trace probes under examples/
- README / STATUS / ROADMAP / docs re-measured: aggregate real-file
  coverage 7.3% -> 20.1% on the 19-file local sample set (R2018 sample
  13.8% -> 44.2%), error table per entity type refreshed
@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_2f089c95-aaf2-4f71-a1ed-88879bc5ea98)

The April decoder-table work added 123 undocumented pub fns, tripping the
docs-rs workflow's 80% soft gate. Each now carries a one-line doc naming
the ODA bit code, flag mask, or spec code it implements; no behavior
changes.
@DrunkOnJava
DrunkOnJava merged commit 44609c2 into main Aug 30, 2026
18 of 20 checks passed
@DrunkOnJava
DrunkOnJava deleted the wip/april-decoder-tables branch August 30, 2026 10:04
DrunkOnJava added a commit that referenced this pull request Aug 30, 2026
…94, refs #17) (#19)

* test(ci): commit a self-generated canonical DWG corpus and make coverage-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.

* ci(perf): gate criterion regressions on ratio + absolute delta + a confirming 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.

* chore(git): ignore the target-msrv/ CARGO_TARGET_DIR used for MSRV checks
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