Skip to content

DXF writer: look table records' extension dictionaries up in linear time - #652

Merged
HakanSeven12 merged 2 commits into
hakanaktt:mainfrom
mcihad:fix/dxf-extension-dictionary-lookup
Nov 24, 2026
Merged

HakanSeven12 merged 2 commits into
hakanaktt:mainfrom
mcihad:fix/dxf-extension-dictionary-lookup

Conversation

@mcihad

@mcihad mcihad commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #651

The DXF writer asks every table record for its extension dictionary. For a record that names none, CadDocument::extension_dictionary_handle walks every object of the document, so writing is quadratic in block records × objects.

Commits

  1. 30ce707 Test that writing a DXF scales linearly with blocks and objects: tests only (tests/dxf_write_scaling.rs), red.
    • The drawing has n blocks of one line and n model-space lines, each with an extension dictionary. It is written with n = 3 000 and then 12 000.
    • The test asks for a time ratio under 9 (linear is 4, quadratic 16) and checks that every extension dictionary is still written.
    • On main (debug build): 3000 blocks 316ms, 12000 blocks 4.48s, ratio 14.2. It fails.
  2. 1a429fc Gather the dictionaries' owners once per DXF write: the fix.
    • CadDocument::owned_dictionaries walks objects once and keeps the first dictionary per owner, in the same order as the walk's find_map.
    • extension_dictionary_handle_in answers the walk's step from that map. The lookup's earlier steps are shared through extension_dictionary_handle_or, not copied.
    • SectionWriter gathers the map once in write_sections (gather_owned_dictionaries) and uses it for table headers and table records. A writer built without it, as table_tests.rs builds one, walks as before.
    • extension_dictionary_handle keeps its signature and its behaviour.
    • Includes a CHANGELOG entry.

Results

  • tests/dxf_write_scaling.rs: 3000 blocks 81ms, 12000 blocks 331ms, ratio 4.1. It passes.
  • A real 32 MB DWG (AC1032, 507 811 objects, 16 027 block records), decoded and written with DxfWriter::write_to_vec in a release build (447 MB of DXF):
    • main: 112.3 s;
    • this branch: 2.95 s.
    • The timing harness was temporary and is not committed.

What I ran

cargo test on 1a429fc (debug, all targets of the crate): 322 test binaries, 3 271 passed, 0 failed, 82 ignored. The three compiler warnings in src/classes/civil/ are on main too.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GBAJR1pu3dhJEV6kKtxAfp

mcihad and others added 2 commits November 24, 2026 16:03
Four times the block records and dictionary objects take 14.2 times as long to write (316 ms -> 4.48 s in a debug
build): every block record that names no extension dictionary has its owner looked up in every object of the
document. Red until the lookup is gathered once per write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GBAJR1pu3dhJEV6kKtxAfp
The writer asked CadDocument::extension_dictionary_handle for every table record, and for a record naming no
extension dictionary the lookup walked every object of the document: quadratic in records times objects. The
writer now gathers each dictionary's owner once (CadDocument::owned_dictionaries, first match in the objects'
order, as the walk's find_map) and answers the walk's step from it; the lookup's other steps are shared, not
copied, and extension_dictionary_handle itself is unchanged.

tests/dxf_write_scaling.rs: ratio 14.2 -> 4.1 (debug). A 32 MB DWG (507 811 objects, 16 027 block records)
written to DXF in a release build: 112.3 s -> 2.95 s.

Closes hakanaktt#651

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GBAJR1pu3dhJEV6kKtxAfp
@mcihad
mcihad marked this pull request as ready for review November 24, 2026 13:20
@HakanSeven12
HakanSeven12 merged commit 1ffc3a5 into hakanaktt:main Nov 24, 2026
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.

Writing a DXF is quadratic in block records × objects: extension_dictionary_handle walks every object

2 participants