From 5bb6a92235f0a1b28aa5d548c5efa694bbeebb52 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Fri, 5 Jun 2026 08:58:39 +0300 Subject: [PATCH] perf(io): parallelize corrupt-entity detection scan The purge scan tests every entity with is_entity_corrupt, whose per-vertex finite/extent checks on large polylines dominate. Detection is pure and read-only, so gather entity refs in one pass and test across cores with rayon; removal stays serial (remove_entity needs &mut doc). Cuts the "purge" span in the open-time breakdown on polyline-heavy files. Co-Authored-By: Claude Opus 4.8 --- src/io/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/io/mod.rs b/src/io/mod.rs index 402b61f21..d81ea960a 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -345,8 +345,14 @@ pub(crate) fn is_entity_corrupt(e: &EntityType) -> bool { } pub fn purge_corrupt_entities(doc: &mut CadDocument) -> usize { - let bad: Vec = doc - .entities() + use rayon::prelude::*; + // Detection is pure and read-only; the per-vertex finite/extent checks on + // large polylines dominate, so fan the scan out across cores. Gather + // entity references in one pass, test in parallel, then remove serially + // (`remove_entity` needs `&mut doc`). + let entities: Vec<&EntityType> = doc.entities().collect(); + let bad: Vec = entities + .par_iter() .filter(|e| is_entity_corrupt(e)) .map(|e| e.common().handle) .collect();