Skip to content

Commit

Permalink
Strip Generics.
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed Mar 20, 2022
1 parent a7aac49 commit d8e96a6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
16 changes: 8 additions & 8 deletions packages/yew/src/html/component/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ impl Runnable for UpdateRunner {
if schedule_render {
scheduler::push_component_render(
state.comp_id,
RenderRunner {
Box::new(RenderRunner {
state: self.state.clone(),
},
}),
);
// Only run from the scheduler, so no need to call `scheduler::start()`
}
Expand Down Expand Up @@ -377,9 +377,9 @@ impl RenderRunner {

scheduler::push_component_render(
state.comp_id,
RenderRunner {
Box::new(RenderRunner {
state: shared_state,
},
}),
);
} else {
// We schedule a render after current suspension is resumed.
Expand All @@ -393,9 +393,9 @@ impl RenderRunner {
suspension.listen(Callback::from(move |_| {
scheduler::push_component_render(
comp_id,
RenderRunner {
Box::new(RenderRunner {
state: shared_state.clone(),
},
}),
);
scheduler::start();
}));
Expand Down Expand Up @@ -442,10 +442,10 @@ impl RenderRunner {

scheduler::push_component_rendered(
state.comp_id,
RenderedRunner {
Box::new(RenderedRunner {
state: self.state.clone(),
first_render,
},
}),
first_render,
);
}
Expand Down
32 changes: 16 additions & 16 deletions packages/yew/src/html/component/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ mod feat_ssr {

scheduler::push_component_create(
self.id,
CreateRunner {
Box::new(CreateRunner {
initial_render_state: state,
props,
scope: self.clone(),
},
RenderRunner {
}),
Box::new(RenderRunner {
state: self.state.clone(),
},
}),
);
scheduler::start();

Expand All @@ -227,12 +227,12 @@ mod feat_ssr {
let self_any_scope = AnyScope::from(self.clone());
html.render_to_string(w, &self_any_scope).await;

scheduler::push_component_destroy(DestroyRunner {
scheduler::push_component_destroy(Box::new(DestroyRunner {
state: self.state.clone(),

#[cfg(feature = "csr")]
parent_to_detach: false,
});
}));
scheduler::start();
}
}
Expand Down Expand Up @@ -347,10 +347,10 @@ mod feat_csr_ssr {
}

pub(super) fn push_update(&self, event: UpdateEvent) {
scheduler::push_component_update(UpdateRunner {
scheduler::push_component_update(Box::new(UpdateRunner {
state: self.state.clone(),
event,
});
}));
// Not guaranteed to already have the scheduler started
scheduler::start();
}
Expand Down Expand Up @@ -418,14 +418,14 @@ mod feat_csr {

scheduler::push_component_create(
self.id,
CreateRunner {
Box::new(CreateRunner {
initial_render_state: state,
props,
scope: self.clone(),
},
RenderRunner {
}),
Box::new(RenderRunner {
state: self.state.clone(),
},
}),
);
// Not guaranteed to already have the scheduler started
scheduler::start();
Expand Down Expand Up @@ -473,10 +473,10 @@ mod feat_csr {

/// Process an event to destroy a component
fn destroy(self, parent_to_detach: bool) {
scheduler::push_component_destroy(DestroyRunner {
scheduler::push_component_destroy(Box::new(DestroyRunner {
state: self.state,
parent_to_detach,
});
}));
// Not guaranteed to already have the scheduler started
scheduler::start();
}
Expand All @@ -486,10 +486,10 @@ mod feat_csr {
}

fn shift_node(&self, parent: Element, next_sibling: NodeRef) {
scheduler::push_component_update(UpdateRunner {
scheduler::push_component_update(Box::new(UpdateRunner {
state: self.state.clone(),
event: UpdateEvent::Shift(parent, next_sibling),
})
}))
}
}
}
Expand Down
24 changes: 11 additions & 13 deletions packages/yew/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,30 @@ mod feat_csr_ssr {
/// Push a component creation, first render and first rendered [Runnable]s to be executed
pub(crate) fn push_component_create(
component_id: usize,
create: impl Runnable + 'static,
first_render: impl Runnable + 'static,
create: Box<dyn Runnable>,
first_render: Box<dyn Runnable>,
) {
with(|s| {
s.create.push(Box::new(create));
s.render_first.insert(component_id, Box::new(first_render));
s.create.push(create);
s.render_first.insert(component_id, first_render);
});
}

/// Push a component destruction [Runnable] to be executed
pub(crate) fn push_component_destroy(runnable: impl Runnable + 'static) {
with(|s| s.destroy.push(Box::new(runnable)));
pub(crate) fn push_component_destroy(runnable: Box<dyn Runnable>) {
with(|s| s.destroy.push(runnable));
}

/// Push a component render and rendered [Runnable]s to be executed
pub(crate) fn push_component_render(component_id: usize, render: impl Runnable + 'static) {
pub(crate) fn push_component_render(component_id: usize, render: Box<dyn Runnable>) {
with(|s| {
s.render.insert(component_id, Box::new(render));
s.render.insert(component_id, render);
});
}

/// Push a component update [Runnable] to be executed
pub(crate) fn push_component_update(runnable: impl Runnable + 'static) {
with(|s| s.update.push(Box::new(runnable)));
pub(crate) fn push_component_update(runnable: Box<dyn Runnable>) {
with(|s| s.update.push(runnable));
}
}

Expand All @@ -102,12 +102,10 @@ mod feat_csr {

pub(crate) fn push_component_rendered(
component_id: usize,
rendered: impl Runnable + 'static,
rendered: Box<dyn Runnable>,
first_render: bool,
) {
with(|s| {
let rendered = Box::new(rendered);

if first_render {
s.rendered_first.insert(component_id, rendered);
} else {
Expand Down

2 comments on commit d8e96a6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: d8e96a6 Previous: 70c9a71 Ratio
yew-struct-keyed 01_run1k 161.4655 161.1465 1.00
yew-struct-keyed 02_replace1k 183.769 182.751 1.01
yew-struct-keyed 03_update10th1k_x16 356.1915 295.649 1.20
yew-struct-keyed 04_select1k 68.174 58.903 1.16
yew-struct-keyed 05_swap1k 85.619 77.38499999999999 1.11
yew-struct-keyed 06_remove-one-1k 27.417 27.522 1.00
yew-struct-keyed 07_create10k 2036.7255 2043.425 1.00
yew-struct-keyed 08_create1k-after1k_x2 382.6925 365.58 1.05
yew-struct-keyed 09_clear1k_x8 198.2685 196.6215 1.01
yew-struct-keyed 21_ready-memory 0.9634475708007812 0.9634475708007812 1
yew-struct-keyed 22_run-memory 1.45648193359375 1.45648193359375 1
yew-struct-keyed 23_update5-memory 1.4712066650390625 1.5030479431152344 0.98
yew-struct-keyed 24_run5-memory 1.5128326416015625 1.5095291137695312 1.00
yew-struct-keyed 25_run-clear-memory 1.1272430419921875 1.1267204284667969 1.00
yew-struct-keyed 31_startup-ci 1730.658 1733.06 1.00
yew-struct-keyed 32_startup-bt 28.231999999999992 29.949999999999996 0.94
yew-struct-keyed 34_startup-totalbytes 330.5498046875 330.5498046875 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: d8e96a6 Previous: 70c9a71 Ratio
yew-struct-keyed 01_run1k 220.646 161.1465 1.37
yew-struct-keyed 02_replace1k 213.2245 182.751 1.17
yew-struct-keyed 03_update10th1k_x16 400.9445 295.649 1.36
yew-struct-keyed 04_select1k 85.16499999999999 58.903 1.45
yew-struct-keyed 05_swap1k 94.6355 77.38499999999999 1.22
yew-struct-keyed 06_remove-one-1k 32.697 27.522 1.19
yew-struct-keyed 07_create10k 2263.484 2043.425 1.11
yew-struct-keyed 08_create1k-after1k_x2 441.358 365.58 1.21
yew-struct-keyed 09_clear1k_x8 181.694 196.6215 0.92
yew-struct-keyed 21_ready-memory 0.9634475708007812 0.9634475708007812 1
yew-struct-keyed 22_run-memory 1.45648193359375 1.45648193359375 1
yew-struct-keyed 23_update5-memory 1.4602203369140625 1.5030479431152344 0.97
yew-struct-keyed 24_run5-memory 1.5095291137695312 1.5095291137695312 1
yew-struct-keyed 25_run-clear-memory 1.1243438720703125 1.1267204284667969 1.00
yew-struct-keyed 31_startup-ci 1730.9 1733.06 1.00
yew-struct-keyed 32_startup-bt 36.08799999999998 29.949999999999996 1.20
yew-struct-keyed 34_startup-totalbytes 330.5498046875 330.5498046875 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.