Eliminate full Insert entity cloning in block style evaluation, unify
document object environment scans, and guard viewport override queries.
1. Analysis & Architectural Bottleneck:
- In render_graph::InsertStyleSpec::new, an entire Insert struct was cloned
into an EntityType::Insert enum solely to pass to style functions that only
read EntityCommon fields (layer, color, transparency, linetype, lineweight).
- In view::render::resolve_document_render_environment, when object caches were
not prepared, the document.objects map was traversed linearly twice: once
for RenderEnvironment and once for RenderSettings.
- Viewport override lookups were being performed even when viewport was None
(the standard model space condition).
2. Optimizations Implemented:
- Added `render_style_for_common_viewport`, `linetype_name_for_common_viewport`,
and `has_resolved_book_color_common` taking `&EntityCommon` directly.
- Constructed `InsertStyleSpec::new` without cloning the Insert entity.
- Fused the two linear scans of `self.document.objects` in
`resolve_document_render_environment` into a single pass tracking best candidates.
- Guarded viewport override lookups with `if viewport.is_some()` in
`layer_render_style_viewport` and `render_style_for_common_viewport`.
3. Correctness & Invariance:
- The same fields and fallback values are resolved in identical order.
- Tested across all 325 scene tests, block inheritance tests, and viewport
override unit tests with 0 failures.
4. Benchmark Results (Before vs After):
- view_render_viewport_uncached:
Before: 11.00 µs (90.9k FPS)
After: 5.00 µs (200.0k FPS)
Improvement: -54.5% latency (2.2x faster uncached rendering)
- wide_and_tapered_arc_tessellation:
Before: 6.36 ms (235.8k entities/s)
After: 5.41 ms (277.4k entities/s)
Improvement: -14.9% latency (+17.6% throughput)
- analytical_curved_tessellation:
Before: 7.79 ms (359.5k entities/s)
After: 7.01 ms (399.6k entities/s)
Improvement: -10.1% latency (+11.1% throughput)
- spatial_interaction_index_build:
Before: 0.77 ms (2.47M wires/s)
After: 0.73 ms (2.66M wires/s)
Improvement: -5.1% latency (+7.7% throughput)
- ui_grip_budget_build:
Before: 424.50 µs
After: 380.25 µs
Improvement: -10.4% latency
- ui_ribbon_view_construction:
Before: 455.50 µs
After: 382.30 µs
Improvement: -16.1% latency
Resolve curve intersections through cadkernel, retain empty exact results, gather analytic candidates independently of tessellation, and bound material uploads. Preserve large MINSERT data while limiting rendering work; remove obsolete review narratives.
Two independent MINSERT (array INSERT) bugs found while auditing
render_graph.rs:
1. array_offsets() reserved and filled one Vec element per array
instance, with row_count/column_count parsed as unchecked u16s.
A corrupt or adversarial 65535x65535 pair requests 4,294,836,225
instances (~96 GiB) before any GPU-side chunking limit can help,
and before the render graph even reaches the GPU. Fixed with a
documented instance budget (20,000) enforced at both the load-time
corrupt-entity filter (is_entity_corrupt, matching the existing
polyline/spline vertex-count guards) and a failsafe clamp in
array_offsets itself, for an insert built or edited some other way.
2. insert_instance_transform composed the per-instance row/column
offset translation *before* the INSERT's own transform, so the
block's x/y scale multiplied the spacing along with the block
contents — an INSERT with x-scale 2 and column spacing 10 rendered
20 units between columns instead of 10. The pinned CAD model's own
Insert::array_points() confirms the correct behavior: spacing
rotates with the insert but is never scaled. Fixed by orienting the
offset with rotation + OCS only, then translating the already-
composed (scaled) instance transform by that world-space vector.
7 new tests cover both: pathological/reasonable instance counts at
the load-time filter and the render-graph failsafe, and instance
transforms for scaled and rotated arrays.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Resolve ByBlock alpha independently from color and keep explicit opaque values from falling back to layer transparency.
Pin the matching cadcodec API across desktop, plugin, and web targets.
Refs HakanSeven12/cadcodec#2
Route model, paper, viewport and nested block content through one traversal while preserving leaf renderers. Carry decoded material state into mesh shading and harden solid geometry conversion.