forked from 1b-agent/opencadstudio-upstream
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
44eea23c3f
commit
5bb6a92235
1 file changed
+8
-2
+8
-2
@@ -345,8 +345,14 @@ pub(crate) fn is_entity_corrupt(e: &EntityType) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn purge_corrupt_entities(doc: &mut CadDocument) -> usize {
|
pub fn purge_corrupt_entities(doc: &mut CadDocument) -> usize {
|
||||||
let bad: Vec<acadrust::Handle> = doc
|
use rayon::prelude::*;
|
||||||
.entities()
|
// 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<acadrust::Handle> = entities
|
||||||
|
.par_iter()
|
||||||
.filter(|e| is_entity_corrupt(e))
|
.filter(|e| is_entity_corrupt(e))
|
||||||
.map(|e| e.common().handle)
|
.map(|e| e.common().handle)
|
||||||
.collect();
|
.collect();
|
||||||
|
|||||||
Reference in new issue
Block a user