From f25812408697e54fb93e810bb157752f1a8a20a9 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Wed, 4 Nov 2026 01:27:14 +0100 Subject: [PATCH] Component fit chunking: review fixes (#5464) Co-Authored-By: Claude Sonnet 5.5 --- crates/trace/src/layers.rs | 6 +++--- crates/trace/src/tests.rs | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/trace/src/layers.rs b/crates/trace/src/layers.rs index a0f63613b..d9b34cc54 100644 --- a/crates/trace/src/layers.rs +++ b/crates/trace/src/layers.rs @@ -402,8 +402,8 @@ impl Layers<'_> { let path = shape.map_or_else(|| PathData::new(subs), |s| s.path()); Some((path, shape)) }; - // In chunks, so that the anchor budget still stops the work early: a hostile image is refused after at most one - // chunk beyond the limit, not after every component is fitted. + // In chunks, so that the anchor budget still stops the work early: a hostile image is refused after fitting at most + // the rest of one chunk, not after every component is fitted. let accepted = fit_in_chunks(&comps, FIT_CHUNK, fit_comp, |comp, fitted| { let Some((path, shape)) = fitted else { return true }; add(path, comp.pixels, area_stroke, shape, false) @@ -469,7 +469,7 @@ const FIT_CHUNK: usize = 256; fn fit_in_chunks(items: &[T], chunk: usize, fit: impl Fn(&T) -> R + Sync, mut accept: impl FnMut(&T, R) -> bool) -> bool { for part in items.chunks(chunk.max(1)) { // (A few components are not worth starting threads for.) - let fitted = if part.len() < 4 { part.iter().map(&fit).collect() } else { parallel_map(part, &fit) }; + let fitted = if part.len() < 16 { part.iter().map(&fit).collect() } else { parallel_map(part, &fit) }; for (item, result) in part.iter().zip(fitted) { if !accept(item, result) { return false; diff --git a/crates/trace/src/tests.rs b/crates/trace/src/tests.rs index c31d3841c..6b3298a7b 100644 --- a/crates/trace/src/tests.rs +++ b/crates/trace/src/tests.rs @@ -630,6 +630,8 @@ fn many_components_come_out_in_scan_order_and_still_meet_the_budget() { assert_eq!(trace(&img, &p), full, "tracing twice differs"); let anchors = full.anchor_count(); assert!(matches!(trace_within(&img, &p, anchors / 2), Err(TraceError::TooComplex { max }) if max == anchors / 2)); + // The last component alone is over the budget: a refusal in a later chunk. + assert!(matches!(trace_within(&img, &p, anchors - 1), Err(TraceError::TooComplex { .. }))); assert_eq!(trace_within(&img, &p, anchors).unwrap(), full); }