Driver: remove the unecessary Boxing of RenderedStimulus

no obvious perf diff one way or the other, yet
This commit is contained in:
2022-08-23 23:33:22 -07:00
parent 4525bbde56
commit b16316b75b

View File

@@ -282,7 +282,7 @@ where
trace!("step begin");
self.diag.instrument_step(steps_this_time as u64, || {
self.state.step_multiple(steps_this_time, &*stim);
self.state.step_multiple(steps_this_time, &stim);
});
trace!("step end");
@@ -456,7 +456,7 @@ struct StimAccess<R, T> {
/// queue)?
/// A.K.A. "can i safely do a blocking recv on response_channel".
outstanding: Cell<bool>,
worker: JobPool<(SimMeta<f32>, u64), (SimMeta<f32>, u64, Box<RenderedStimulus<R>>)>,
worker: JobPool<(SimMeta<f32>, u64), (SimMeta<f32>, u64, RenderedStimulus<R>)>,
}
impl<R, T> StimAccess<R, T> {
@@ -483,7 +483,7 @@ impl<R, T> StimAccess<R, T> {
/// waits for an outstanding job (if any).
/// if the response matches the request, return the response,
/// else discard the response.
fn maybe_wait_for_job(&self, meta: SimMeta<f32>, step: u64) -> Option<Box<RenderedStimulus<R>>> {
fn maybe_wait_for_job(&self, meta: SimMeta<f32>, step: u64) -> Option<RenderedStimulus<R>> {
if !self.outstanding.get() {
return None;
}
@@ -501,7 +501,7 @@ impl<R, T> StimAccess<R, T> {
}
impl<R: Real, T: DriverStimulus<R> + Send + 'static> StimAccess<R, T> {
fn get_for(&mut self, meta: SimMeta<f32>, step: u64) -> Box<RenderedStimulus<R>> {
fn get_for(&mut self, meta: SimMeta<f32>, step: u64) -> RenderedStimulus<R> {
// either claim the outstanding job (if it exists and matches)...
self.maybe_wait_for_job(meta, step).unwrap_or_else(|| {
// or start a job and wait for it to complete inline
@@ -529,14 +529,13 @@ impl<R: Real, T: DriverStimulus<R> + Send + 'static> StimAccess<R, T> {
let stim = diag.instrument_stimuli(|| {
let stim = stim.lock().unwrap();
let opt = stim.optimized_for(meta, step);
// TODO: remove this box. RenderedStimulus is already heap allocated, so no perf diff?
Box::new(opt.as_ref().rendered(
opt.as_ref().rendered(
meta.time_step().cast(),
// TODO: convert this to an integer
meta.time_step().cast::<R>() * R::from_primitive(step),
meta.feature_size().cast(),
meta.dim()
).into_owned())
).into_owned()
//^ this 'into_owned' ought to be a no-op.
//^ it would only ever be borrowed if we accidentally called `rendered` twice.
});