Skip to content

perf(streaming): add the §4.2 page checksum in eight lanes (#205) - #362

Merged
DrunkOnJava merged 2 commits into
mainfrom
perf/stream-page-checksum
Oct 27, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
perf/stream-page-checksum

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

The §4.2 page checksum of the R2004 family (the data pages' and the system pages') ran sum1 += byte; sum2 += sum1 one byte at a time with a counter test per byte. crc::fold_section_checksum runs whole rows of eight bytes as eight independent lanes of the same recurrence, vertical additions only, and combines the lanes once per slice, with the modulo reduction at the same 0x15B0-byte boundaries as before. The (sum1, sum2, in_chunk) it leaves equals the byte-at-a-time loop's after every slice, so a checkpoint is byte-identical.

Profile (Time Profiler, R2010 streaming walk after the CRC-8 change in the sibling PR): the loop and its slice iterator were about 12% of the samples. In isolation (a scratch microbenchmark, not committed) 1.3 MB in 64-byte reads takes 0.27 ms against 0.61 ms. A first formulation (eight bytes weighted and summed) was 0.63 times as fast as the loop and was dropped.

Streaming walk, best of 40 in memory (examples/stream_throughput, Apple M2 Max under load), against origin/main at a315f04:

Release Drawing Before After
R2004 sample_AC1018 5.76 ms 5.32 ms x1.08
R2010 sample_AC1024 7.05 ms 6.64 ms x1.06
R2013 sample_AC1027 5.45 ms 4.98 ms x1.09
R2018 sample_AC1032 5.44 ms 4.99 ms x1.09

R14 and R2000 do not run this loop and did not move (3.27 to 3.39 ms, within noise).

Spec reference

§4.2 (the section page checksum), 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, the sibling 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 §4.2 checksum on real drawings, from release builds with overflow checks and debug assertions (CI runs the debug ones): verify_maps.py (page map and section map), verify_sections.py (33 files, 409 sections, 603 pages), verify_file.py (35 files, 423 sections, 625 pages), verify_wasm.py (native and wasm32 checkpoints byte-identical), verify_objects.py (32 files, 8,027 records), verify_wasm_objects.py. All passed; each writes its binary SHA to its evidence JSON.
  • A scratch differential check of fold_section_checksum against the byte-at-a-time loop: the state (sum1, sum2, in_chunk) equal after each of 215,229 random slices of random data, seeds up to 0xFFFF, across the 0x15B0 reductions. Not committed (no unit tests): a wrong checksum fails every page of the verifiers above.
  • Throughput (the table above): cargo build --release --example stream_throughput, then target/release/examples/stream_throughput <corpus>/acadsharp/sample_AC10{14,15,18,24,27,32}.dwg --runs 40, 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.

@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 🔄 Running since 2026-10-27T04:15:41.405251Z adda035 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.

The R2004-family system-page and data-page checksums (§4.2) ran a
byte-at-a-time recurrence (sum1 += byte; sum2 += sum1) with a counter test
per byte. In the Time Profiler line profile of the streaming R2010 walk
(after the CRC-8 change) the loop and its slice iterator were about 12% of
the samples.

crc::fold_section_checksum runs whole rows of eight bytes as eight independent
lanes of the same recurrence (vertical additions only) and combines the lanes
once per slice, breaking at the same 0x15B0-byte reductions. The state it
leaves, (sum1, sum2, in_chunk), equals the byte-at-a-time loop's after every
slice, so checkpoints are byte-identical. The first version tried (a weighted
sum over eight bytes) was slower than the loop and was dropped.

A scratch differential check against the old loop (not committed) compared
the state after 215,229 random slices of random data across reductions, with
seeds up to 0xFFFF. In isolation 1.3 MB in 64-byte reads takes 0.27 ms against
0.61 ms.

Streaming walk, best of 40 in memory (examples/stream_throughput), against
origin/main, Apple M2 Max under load:

  R2004  sample_AC1018  5.76 ms -> 5.32 ms  (x1.08)
  R2010  sample_AC1024  7.05 ms -> 6.64 ms  (x1.06)
  R2013  sample_AC1027  5.45 ms -> 4.98 ms  (x1.09)
  R2018  sample_AC1032  5.44 ms -> 4.99 ms  (x1.09)
@DrunkOnJava
DrunkOnJava force-pushed the perf/stream-page-checksum branch from cea7af5 to 9b434d6 Compare October 27, 2026 03:38
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