Repository navigation
io: saving a drawing of thousands of blocks no longer takes quadratic time; scaling test (FF6) - #1938
francescoBV wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
ASCII DXF formatting crates/dxf/src/lib.rs |
ASCII output uses append-based helpers for group codes and values. Tests compare the new formatting with previous formatting and check representative output. |
Raw tag processing crates/io/src/dxf_raw.rs |
Raw DXF handling borrows text for eligible tag values, shares section names, and parses handles directly in applicable paths. |
Record output and class counts crates/io/src/dxf_raw.rs, crates/io/src/dxf_write/sections.rs |
Output assembly moves existing tags instead of cloning them. Unknown block end records are indexed in one pass, and missing class-count tags are inserted in one pass. |
Large-drawing validation and documentation crates/io/tests/it/large_drawing_perf.rs, crates/io/tests/it/main.rs, docs/gaps.md |
Integration tests generate large drawings and check content, round-trip time bounds, and scaling ratios. The documentation records save timings, the scaling threshold, and remaining gaps. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Possibly related issues
storytold/cadcraftissue 1077: The issue describes slow DXF saves on large drawings and hash-map work indxf_raw::finish; this change modifies that save path and indexes block end records in one pass.storytold/cadcraftissue 1076: The issue asks about write-side memory use in the DWG conversion path; this change moves existing tag groups into output instead of cloning them.
Suggested reviewers: vangel76, aiongg
Merge Risk: 
Minimal · up to 47b69
-
The DXF performance changes appear ready to merge after normal checks.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the primary change: saving a drawing with thousands of blocks no longer takes quadratic time. The objectives confirm this is the main goal, with DXF and DWG save time reduced for block-heavy drawings. The title also names the scaling test and the FF6 label, which the changeset includes. The title is specific and matches the changeset. It is somewhat long at 94 characters and 16 words, but it stays on topic and does not use vague terms.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 24 functions across 5 files. (1 skipped: 1 unsupported.)
-
Finishing Touches: 💡 1
-
⚔️ Resolve merge conflicts: 💡
-
- Resolve merge conflict in branch
pr/dxf-save-speed
- Resolve merge conflict in branch
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
… time; scaling test (FF6) Saving a drawing reopened from its own file looked up each block's ENDBLK by scanning all records (dxf_raw::plan_unknown), and inserted every CLASS instance count with Vec::insert, moving the whole tag list once per class. Both are now one pass. dxf_raw::finish moves the written groups into its output instead of cloning them, the passes over a written file borrow group text instead of copying it (Rec's section name is shared), and the ASCII writer formats group codes, reals and plain text without format!. crates/io/tests/large_drawing_perf.rs generates drawings in code: a 20,000-entity DXF/DWG round trip under a generous bound, and a scaling check that four times the entities (and blocks) take less than nine times as long to open and save as DXF and DWG. On main the DXF save step takes 16x as long; with this change about 5x. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
11248fa to
47b6979
Compare
…ADCraft PRs) (#924) * dxf: write group codes, reals and plain text without the formatting machinery write_ascii and its code page forms wrote every group code through write!("{:>3}"), every real through a String of its own and every string character by character. A large drawing writes millions of each. Codes 0 to 9999 and reals are now appended in place, and text with no line break or backslash that is ASCII (or goes out as UTF-8) is copied as it is. Text for a code page still takes the long path, since a code page may write an ASCII character another way. The output is byte for byte what it was. Ported from storytold/cadcraft#1938 (the crates/dxf part). * dxf: parse_recovering reads a damaged or truncated ASCII file up to the damage parse fails a file at the first line that is no group code, and at a last group code with no value. parse_recovering returns the tags before that point and the line where reading stopped, so a caller can open what the file still holds and say where it ends. Reading stops at the damage: lines after it are not paired up by guesswork. Damage before the first group, a truncated binary file and the group-code limit are still errors. section_slices ends a section at EOF as well as ENDSEC, so the EOF of a file cut inside a section is not one of that section's records. Ported from storytold/cadcraft#1565 (the crates/dxf part). --------- Co-authored-by: Francesco BV <francesco.esposito@bvitalia.net> Co-authored-by: Alex Ortiz <76929676+aljormon84@users.noreply.github.com>
Requested by Francesco BV
Before: saving a drawing that was opened from a file took time that grew with the square of its blocks.
dxf_raw::finishfound each block's ENDBLK by scanning every written record (plan_unknown), andadd_class_instance_countsadded each CLASS record's group 91 withVec::insert, which moves the whole tag list once per class. A drawing of 12,000 entities and 6,000 small blocks, opened and saved again as DXF, took 8.4 s (release); 3,000 entities took 0.5 s, so 4x the entities cost 16.7x the time. DWG saves go through the same DXF writer, so they had the same problem.After: the same save takes 0.6 s (3,000 entities: 0.11 s). Four times the entities now take about four to six times as long to open or save, as DXF or DWG.
How:
plan_unknownbuilds a map from block name to ENDBLK in one pass over the records.add_class_instance_countscollects the 91 groups and inserts them all in one rebuild of the list.finishmoves the written groups into its output withmem::replaceinstead of cloning them. The passes over a written file (head,head_handle,foreign_xdata,record,add_appids, the handle seed) read group text through a borrowedtext()instead ofTag::str(), andRecshares its section name (Rc<str>). Incrates/dxf,write_ascii_aswrites group codes and reals withoutformat!(push_code,push_real) and copies plain ASCII text without checking each character. The output is byte for byte the same as before. This branch doesn't change reading, so it doesn't overlap #1708.docs/gaps.mdrow FF6 and its revision history are updated.Overlaps: #1833 and #1588 also read group text without a copy in the
head()/foreign_xdata()/written_records()lines ofcrates/io/src/dxf_raw.rs(#1833 addsdxf_ext::text), so whichever lands second needs a small rebase there. #1708, #1588, #1833 and #1835 speed up reading. This PR speeds up saving, and they don't duplicate each other.docs/gaps.md(header line, FF6 row, revision history) will conflict textually with my other open PRs #1909, #1910 and #1911 and with the rest of this batch. #1911 also editscrates/dxf/src/lib.rsandcrates/io/src/dxf_write.rs, but in other functions.Tests
crates/io/tests/large_drawing_perf.rs(new; drawings generated in code, no fixtures):generated_drawing_holds_what_was_asked;mid_size_drawing_opens_and_round_trips_in_time(20,000 entities through DXF and DWG, 60 s bound);opening_and_saving_scale_linearly(3,000 vs 12,000 entities with a block for every two: DXF/DWG open and save must stay under 9x; on main the DXF save step fails at 14–17x);write_large_corpus(#[ignore], writes 100k–1M-entity files for profiling)crates/dxf/src/lib.rs:fast_code_and_real_formatting_match_format(codes from -1,000,000 to 1,000,000, reals including -0.0, 1e21,f64::MAX, NaN and infinity, and line breaks, non-ASCII and plain text match the oldformat!output)cargo fmt --all -- --check,cargo clippy -p cadcraft-dxf -p cadcraft-io --all-targets -- -D warnings,cargo test -p cadcraft-dxf -p cadcraft-io,cargo xtask layers,cargo check --target wasm32-unknown-unknown -p cadcraft-dxf -p cadcraft-io🤖 Generated with Claude Code
Summary by CodeRabbit