From a5ded805011c06881d1f0fc46115325e1c0993db Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Wed, 21 Feb 2024 08:17:51 -0500 Subject: [PATCH] Small optimization to reuse shapes if simplification didn't help --- fidget/src/render/render3d.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/fidget/src/render/render3d.rs b/fidget/src/render/render3d.rs index ea2c4c44..45cd4ba3 100644 --- a/fidget/src/render/render3d.rs +++ b/fidget/src/render/render3d.rs @@ -160,18 +160,24 @@ impl Worker<'_, S> { return; } - // Calculate a simplified tape, reverting to the parent tape if the - // simplified tape isn't any shorter. + // Calculate a simplified tape based on the trace let mut sub_tape = if let Some(trace) = trace.as_ref() { let s = self.shape_storage.pop().unwrap_or_default(); let next = shape.shape.simplify(trace, s, &mut self.workspace).unwrap(); - Some(ShapeAndTape { - shape: next, - i_tape: None, - f_tape: None, - g_tape: None, - }) + if next.size() >= shape.shape.size() { + // Optimization: if the simplified shape isn't any shorter, then + // don't use it (this saves time spent generating tapes) + self.shape_storage.extend(next.recycle()); + None + } else { + Some(ShapeAndTape { + shape: next, + i_tape: None, + f_tape: None, + g_tape: None, + }) + } } else { None };