Skip to content

Commit

Permalink
Small optimization to reuse shapes if simplification didn't help
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Feb 21, 2024
1 parent 6db5f1b commit a5ded80
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions fidget/src/render/render3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,24 @@ impl<S: Shape> 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
};
Expand Down

0 comments on commit a5ded80

Please sign in to comment.