Skip to content

Commit 42b315b

Browse files
committed
fix rebase fallout + use Arc<str> more for reducers
1 parent 6fc632b commit 42b315b

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

crates/core/src/db/relational_db.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2424,9 +2424,9 @@ mod tests {
24242424
arg_bsatn,
24252425
} = ReducerContext::try_from(&input).unwrap();
24262426
if i == 0 {
2427-
assert_eq!(reducer_name, "__identity_connected__");
2427+
assert_eq!(&*reducer_name, "__identity_connected__");
24282428
} else {
2429-
assert_eq!(reducer_name, "abstract_concrete_proxy_factory_impl");
2429+
assert_eq!(&*reducer_name, "abstract_concrete_proxy_factory_impl");
24302430
}
24312431
assert!(
24322432
arg_bsatn.is_empty(),

crates/core/src/execution_context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct ExecutionContext {
2626
#[derive(Clone)]
2727
pub struct ReducerContext {
2828
/// The name of the reducer.
29-
pub name: String,
29+
pub name: Arc<str>,
3030
/// The [`Identity`] of the caller.
3131
pub caller_identity: Identity,
3232
/// The [`Address`] of the caller.
@@ -81,7 +81,7 @@ impl TryFrom<&txdata::Inputs> for ReducerContext {
8181
let timestamp = bsatn::from_reader(args)?;
8282

8383
Ok(Self {
84-
name: inputs.reducer_name.to_string(),
84+
name: inputs.reducer_name.as_str().into(),
8585
caller_identity,
8686
caller_address,
8787
timestamp,
@@ -200,7 +200,7 @@ impl ExecutionContext {
200200
/// If this is a reducer context, returns the name of the reducer.
201201
#[inline]
202202
pub fn reducer_name(&self) -> &str {
203-
self.reducer.as_ref().map(|ctx| ctx.name.as_str()).unwrap_or_default()
203+
self.reducer.as_ref().map(|ctx| &*ctx.name).unwrap_or_default()
204204
}
205205

206206
/// If this is a reducer context, returns the full reducer metadata.

crates/core/src/host/module_host.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ impl ModuleHost {
592592
let db = self.db();
593593
let workload = || {
594594
Workload::Reducer(ReducerContext {
595-
name: reducer_name.to_owned(),
595+
// TODO(perf, centril): consider allowing `&'static str | Arc<str>`, perhaps flexstr.
596+
name: reducer_name.into(),
596597
caller_identity,
597598
caller_address,
598599
timestamp: Timestamp::now(),
@@ -794,7 +795,7 @@ impl ModuleHost {
794795
tx.ctx = ExecutionContext::with_workload(
795796
tx.ctx.database_identity(),
796797
Workload::Reducer(ReducerContext {
797-
name: reducer.into(),
798+
name: reducer,
798799
caller_identity: params.caller_identity,
799800
caller_address: params.caller_address,
800801
timestamp: Timestamp::now(),
@@ -932,9 +933,7 @@ impl ModuleHost {
932933
let db = self.db();
933934
let auth = self.auth_ctx_for(identity);
934935
let (table_names, table_ids): (Vec<_>, Vec<_>) = db
935-
.with_read_only(&ExecutionContext::internal(db.database_identity()), |tx| {
936-
db.get_all_tables(tx)
937-
})
936+
.with_read_only(Workload::Internal, |tx| db.get_all_tables(tx))
938937
.expect("ids_to_name: database in a broken state?")
939938
.iter()
940939
.filter(|schema| is_table_visible(schema, &auth))

crates/core/src/host/wasm_common/module_host_actor.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
429429

430430
let op = ReducerOp {
431431
id: reducer_id,
432-
name: reducer_name,
432+
name: reducer_name_arc.clone(),
433433
caller_identity: &caller_identity,
434434
caller_address: &caller_address,
435435
timestamp,
@@ -444,7 +444,7 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
444444
});
445445
let _guard = WORKER_METRICS
446446
.reducer_plus_query_duration
447-
.with_label_values(&address, op.name)
447+
.with_label_values(&address, reducer_name)
448448
.with_timer(tx.timer);
449449

450450
let mut tx_slot = self.instance.instance_env().tx.clone();
@@ -576,7 +576,7 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
576576
#[derive(Clone, Debug)]
577577
pub struct ReducerOp<'a> {
578578
pub id: ReducerId,
579-
pub name: &'a str,
579+
pub name: Arc<str>,
580580
pub caller_identity: &'a Identity,
581581
pub caller_address: &'a Address,
582582
pub timestamp: Timestamp,
@@ -596,7 +596,7 @@ impl From<ReducerOp<'_>> for execution_context::ReducerContext {
596596
}: ReducerOp<'_>,
597597
) -> Self {
598598
Self {
599-
name: name.to_owned(),
599+
name,
600600
caller_identity: *caller_identity,
601601
caller_address: *caller_address,
602602
timestamp,

crates/core/src/host/wasmtime/wasm_instance_env.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(clippy::too_many_arguments)]
22

3+
use std::sync::Arc;
34
use std::time::Instant;
45

56
use crate::database_logger::{BacktraceFrame, BacktraceProvider, ModuleBacktrace, Record};
@@ -72,7 +73,7 @@ pub(super) struct WasmInstanceEnv {
7273
call_times: CallTimes,
7374

7475
/// The last, including current, reducer to be executed by this environment.
75-
reducer_name: String,
76+
reducer_name: Arc<str>,
7677
}
7778

7879
const CALL_REDUCER_ARGS_SOURCE: u32 = 1;
@@ -96,7 +97,7 @@ impl WasmInstanceEnv {
9697
timing_spans: Default::default(),
9798
reducer_start,
9899
call_times: CallTimes::new(),
99-
reducer_name: String::from(""),
100+
reducer_name: "".into(),
100101
}
101102
}
102103

@@ -138,7 +139,7 @@ impl WasmInstanceEnv {
138139
///
139140
/// Returns the handle used by reducers to read from `args`
140141
/// as well as the handle used to write the error message, if any.
141-
pub fn start_reducer(&mut self, name: &str, args: bytes::Bytes) -> (u32, u32) {
142+
pub fn start_reducer(&mut self, name: Arc<str>, args: bytes::Bytes) -> (u32, u32) {
142143
let errors = self.setup_standard_bytes_sink();
143144

144145
// Pass an invalid source when the reducer args were empty.
@@ -151,7 +152,7 @@ impl WasmInstanceEnv {
151152
};
152153

153154
self.reducer_start = Instant::now();
154-
name.clone_into(&mut self.reducer_name);
155+
self.reducer_name = name;
155156

156157
(args, errors)
157158
}

0 commit comments

Comments
 (0)