Skip to content

perf(streaming): slice the R2007 CRC-64s, checksum and syndromes (#205) - #366

Merged
DrunkOnJava merged 2 commits into
mainfrom
perf/stream-r2007-checks
Oct 27, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
perf/stream-r2007-checks

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

Three checks of the R2007 walk ran a byte at a time. Now: the two CRC-64s (§5.12; 8-byte blocks taken as 6 7 4 5 2 3 0 1) take whole blocks straight from the slice and fold eight bytes per step with slicing tables built at compile time; the §5.4.1 page checksum adds eight lanes of its recurrence vertically in the block order and combines them once per slice, reducing at the same 0x15B0-byte boundaries; the Reed-Solomon syndromes (§5.13) use one multiplication-table lookup per byte per syndrome instead of a log, an exp and a zero test. Checkpoints are unchanged.

Profile (Time Profiler, the streaming R2007 walk of sample_AC1021.dwg alone): the checksum was 14.6% of the samples, the CRC-64s 12.3%, the syndromes 10.3% (6.2% more in their iterator).

A scratch differential check against the old code (not committed) compared 728,266 cases: both CRC-64 flavours' state and the checksum's state after every update of random slices (seeds, lengths and slicings random, across the 0x15B0 reductions), and the whole syndrome vector of 40,000 random words for both codes.

R2007 streaming walk, best of 15 in memory (examples/stream_r2007_timing, Apple M2 Max under load), against origin/main at a315f04:

Drawing Before After
sample_AC1021 (1.06 MB) 20.63 ms, 51.5 MB/s 12.85 ms, 82.7 MB/s x1.61

Together with the sibling copy-table PR the R2007 walk goes from 20.24 ms to 7.95 ms (x2.55), measured on the two merged.

Spec reference

§5.12 (the CRC-64s), §5.4.1 (the checksum), §5.13 (the Reed-Solomon codes), unchanged in meaning. Performance only: part of #205. No format finding, no coverage-state change.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
  • cargo +1.85 check --all-features (MSRV)
  • cargo test --release --all-features (existing suites only; no test added; built without LTO to fit the machine's CPU budget, perf(streaming): fold eight bytes per step in the DWG CRC-8 (#205) #360 ran the full LTO profile)
  • python3 tools/streaming/check_invariants.py; tools/streaming/no_std.rs compiled natively and for wasm32-unknown-unknown, state bounds hold
  • The streaming verifiers that run the CRC-64s, checksum and syndromes on real drawings, from release builds with overflow checks and debug assertions (CI runs the debug ones): verify_r2007.py (the 8 pinned drawings and the files it builds, including a non-zero CRC seed, stored and compressed system pages and a page of 273 codewords: every output line and section byte equal to the independent Python reader and the legacy reader; its corruptions each end in the named R2007Parity, R2007Crc64 or R2007Checksum) and verify_wasm_r2007.py (native and wasm32 checkpoints byte-identical). Both passed; each writes its binary SHA to its evidence JSON.
  • A scratch differential check against the old code: 728,266 comparisons (both CRC-64 flavours' state and the checksum's state after every update of random slices; the whole syndrome vector of 40,000 random words for both codes). Not committed (no unit tests).
  • Throughput (the table above): cargo build --release --example stream_r2007_timing, then target/release/examples/stream_r2007_timing <corpus>/acadsharp/sample_AC1021.dwg 15, build of origin/main against build of this branch, alternated.

Source-provenance declaration

By submitting this PR I certify that my contribution does not incorporate executable code from any source whose license is incompatible with Apache-2.0. Specifically:

  • No Autodesk DWG SDK source (RealDWG, ObjectARX, ObjectDBX) or NDA-protected Autodesk documentation was consulted or imported.
  • No Open Design Alliance Teigha / Drawings SDK source was consulted or imported. The ODA's public Open Design Specification for .dwg files PDF is explicitly allowed (see CLEANROOM.md).
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported. This matters because dwg-rs is Apache-2.0 and must remain compatible.

My contribution is based on:

  • The ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1);
  • Public reverse-engineering notes, research papers, or blog posts cited inline;
  • Reading algorithm-description comments (not executable code) in permissively-licensed projects (MIT / Apache / BSD) to resolve spec ambiguities — disclose any such reading in this PR body so it can be recorded in CLEANROOM.md.

See CLEANROOM.md for the full allowed/forbidden source list and the honest scope of what "clean-room" means for this project.

Developer Certificate of Origin

By submitting this PR, I certify that the contribution complies with the
Developer Certificate of Origin 1.1.
Specifically, I affirm that the contribution is my own work (or rightfully
licensed to me) and that it can be distributed under the project's Apache-2.0
license.

I will sign off commits with git commit -s when asked, which adds a
Signed-off-by trailer to the commit message asserting the DCO.

Three checks of the R2007 walk ran a byte at a time: the two CRC-64s (§5.12,
8-byte blocks taken as 6 7 4 5 2 3 0 1) behind a copy into a block buffer, the
§5.4.1 page checksum, and the Reed-Solomon syndromes (a log and exp lookup and
a zero test per syndrome per byte). In the Time Profiler profile of the
streaming R2007 walk of sample_AC1021 they were about 12% (checksum), 10%
(CRC-64) and 13% (syndromes) of the samples.

Whole blocks now go straight from the slice: the CRC-64s fold eight bytes per
step with slicing tables built at compile time (the permuted block as one
word); the checksum adds eight lanes of its recurrence vertically in the block
order and combines them once per slice, with the reduction at the same
0x15B0-byte boundaries; the syndromes use a multiplication table per root, one
lookup per byte per syndrome. A scratch differential check against the old
code (not committed) compared 728,266 cases: both CRC-64 flavours' state and
the checksum's state after every update of random slices, and the whole
syndrome vector of 40,000 random words for both codes. Checkpoints are
unchanged.

R2007 streaming walk, best of 15 in memory (examples/stream_r2007_timing),
against origin/main, Apple M2 Max under load:

  sample_AC1021  20.63 ms -> 12.85 ms  (x1.61; 51.5 -> 82.7 MB/s of the file)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T07:21:49.125412Z 79ab587 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 27, 2026 07:33
@DrunkOnJava
DrunkOnJava merged commit 5851283 into main Oct 27, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the perf/stream-r2007-checks branch October 27, 2026 07:34
DrunkOnJava added a commit that referenced this pull request Oct 28, 2026
… to what landed (#205, #206, #207) (#400)

The ledger stopped at the header and the R13-R2000 walk, and the README's
checkpoint contract described the header checkpoint alone and said full object
and decompression checkpoints remain open. Both now cover the ten checkpoint
kinds on main and the walkers of #240, #246, #260, #276, #299, #312, #333, #340
and #363, the perf series #360 to #366, and cite the evidence files of Streaming
E2E run 40532346151. What was not measured is marked NOT MEASURED.
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