Skip to content

Commit a69d77e

Browse files
committed
Optimize fast path for recording by avoiding flat type computation
1 parent 742436d commit a69d77e

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

crates/wasmtime/src/runtime/rr/core/events/component_events.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ pub struct LowerMemoryReturnEvent(pub ResultEvent<(), LowerMemoryError>);
224224
#[derive(Debug, Clone, Serialize, Deserialize)]
225225
pub struct WasmFuncReturnEvent(pub ResultEvent<RRFuncArgVals, WasmFuncReturnError>);
226226

227-
impl Validate<Result<RRFuncArgVals>> for WasmFuncReturnEvent {
228-
fn validate(&self, expect: &Result<RRFuncArgVals>) -> Result<(), ReplayError> {
229-
self.0.validate(expect)
227+
impl Validate<&Result<RRFuncArgVals>> for WasmFuncReturnEvent {
228+
fn validate(&self, expect: &&Result<RRFuncArgVals>) -> Result<(), ReplayError> {
229+
self.0.validate(*expect)
230230
}
231231
}
232232

crates/wasmtime/src/runtime/rr/hooks/component_hooks.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ where
6161
})?;
6262
store
6363
.0
64-
.next_replay_event_validation::<WasmFuncReturnEvent, Result<RRFuncArgVals>>(&result)?;
64+
.next_replay_event_validation::<WasmFuncReturnEvent, _, &Result<RRFuncArgVals>>(
65+
|| &result,
66+
)?;
6567
result?;
6668
return Ok(());
6769
}
@@ -80,10 +82,13 @@ pub fn record_replay_host_func_entry(
8082
#[cfg(all(feature = "rr-component", feature = "rr-validate"))]
8183
{
8284
use crate::rr::component_events::HostFuncEntryEvent;
83-
let flat_params = types.flat_types_storage(&InterfaceType::Tuple(types[*type_idx].params));
84-
let event = HostFuncEntryEvent::new(args, flat_params, type_idx.clone());
85-
store.record_event_validation(|| event.clone())?;
86-
store.next_replay_event_validation::<HostFuncEntryEvent, _>(&event)?;
85+
let event = || {
86+
let flat_params =
87+
types.flat_types_storage(&InterfaceType::Tuple(types[*type_idx].params));
88+
HostFuncEntryEvent::new(args, flat_params, type_idx.clone())
89+
};
90+
store.record_event_validation(|| event())?;
91+
store.next_replay_event_validation::<HostFuncEntryEvent, _, _>(|| event())?;
8792
}
8893
let _ = (args, types, type_idx, store);
8994
Ok(())
@@ -98,10 +103,10 @@ pub fn record_host_func_return(
98103
store: &mut StoreOpaque,
99104
) -> Result<()> {
100105
#[cfg(feature = "rr-component")]
101-
{
106+
store.record_event(|| {
102107
let flat_results = types.flat_types_storage(&ty);
103-
store.record_event(|| HostFuncReturnEvent::new_from_flat_storage(args, flat_results))?;
104-
}
108+
HostFuncReturnEvent::new_from_flat_storage(args, flat_results)
109+
})?;
105110
let _ = (args, types, ty, store);
106111
Ok(())
107112
}

crates/wasmtime/src/runtime/rr/hooks/core_hooks.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ pub fn record_replay_host_func_entry(
1818
{
1919
// Record/replay the raw parameter args
2020
use crate::rr::core_events::HostFuncEntryEvent;
21-
let event = HostFuncEntryEvent::new(&args, flat, ty.clone());
22-
store.record_event_validation(|| event.clone())?;
23-
store.next_replay_event_validation::<HostFuncEntryEvent, _>(&event)?;
21+
store.record_event_validation(|| HostFuncEntryEvent::new(&args, flat, ty.clone()))?;
22+
store.next_replay_event_validation::<HostFuncEntryEvent, _, _>(|| {
23+
HostFuncEntryEvent::new(&args, flat, ty.clone())
24+
})?;
2425
}
2526
let _ = (args, flat, ty, store);
2627
Ok(())

crates/wasmtime/src/runtime/store.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,16 +1576,17 @@ impl StoreOpaque {
15761576
/// Convenience wrapper around [`Replayer::next_event_validation`]
15771577
#[cfg(feature = "rr-validate")]
15781578
#[inline]
1579-
pub(crate) fn next_replay_event_validation<T, Y>(
1579+
pub(crate) fn next_replay_event_validation<T, F, Y>(
15801580
&mut self,
1581-
expect: &Y,
1581+
expect: F,
15821582
) -> Result<(), ReplayError>
15831583
where
15841584
T: TryFrom<RREvent> + Validate<Y>,
1585+
F: FnOnce() -> Y,
15851586
ReplayError: From<<T as TryFrom<RREvent>>::Error>,
15861587
{
15871588
if let Some(buf) = self.replay_buffer_mut() {
1588-
buf.next_event_validation::<T, Y>(expect)
1589+
buf.next_event_validation::<T, Y>(&expect())
15891590
} else {
15901591
Ok(())
15911592
}

0 commit comments

Comments
 (0)