Skip to content

Commit

Permalink
fix rebase fallout + use Arc<str> more for reducers
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 30, 2024
1 parent 972e023 commit 6cc4313
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions crates/core/src/db/relational_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2424,9 +2424,9 @@ mod tests {
arg_bsatn,
} = ReducerContext::try_from(&input).unwrap();
if i == 0 {
assert_eq!(reducer_name, "__identity_connected__");
assert_eq!(&*reducer_name, "__identity_connected__");
} else {
assert_eq!(reducer_name, "abstract_concrete_proxy_factory_impl");
assert_eq!(&*reducer_name, "abstract_concrete_proxy_factory_impl");
}
assert!(
arg_bsatn.is_empty(),
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub struct ExecutionContext {
#[derive(Clone)]
pub struct ReducerContext {
/// The name of the reducer.
pub name: String,
pub name: Arc<str>,
/// The [`Identity`] of the caller.
pub caller_identity: Identity,
/// The [`Address`] of the caller.
Expand Down Expand Up @@ -172,7 +172,7 @@ impl TryFrom<&txdata::Inputs> for ReducerContext {
let timestamp = bsatn::from_reader(args)?;

Ok(Self {
name: inputs.reducer_name.to_string(),
name: inputs.reducer_name.as_str().into(),
caller_identity,
caller_address,
timestamp,
Expand Down Expand Up @@ -278,7 +278,7 @@ impl ExecutionContext {
/// If this is a reducer context, returns the name of the reducer.
#[inline]
pub fn reducer_name(&self) -> &str {
self.reducer.as_ref().map(|ctx| ctx.name.as_str()).unwrap_or_default()
self.reducer.as_ref().map(|ctx| &*ctx.name).unwrap_or_default()
}

/// If this is a reducer context, returns the full reducer metadata.
Expand Down
9 changes: 4 additions & 5 deletions crates/core/src/host/module_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ impl ModuleHost {
let db = self.db();
let workload = || {
Workload::Reducer(ReducerContext {
name: reducer_name.to_owned(),
// TODO(perf, centril): consider allowing `&'static str | Arc<str>`, perhaps flexstr.
name: reducer_name.into(),
caller_identity,
caller_address,
timestamp: Timestamp::now(),
Expand Down Expand Up @@ -794,7 +795,7 @@ impl ModuleHost {
tx.ctx = ExecutionContext::with_workload(
tx.ctx.database_identity(),
Workload::Reducer(ReducerContext {
name: reducer.into(),
name: reducer,
caller_identity: params.caller_identity,
caller_address: params.caller_address,
timestamp: Timestamp::now(),
Expand Down Expand Up @@ -932,9 +933,7 @@ impl ModuleHost {
let db = self.db();
let auth = self.auth_ctx_for(identity);
let (table_names, table_ids): (Vec<_>, Vec<_>) = db
.with_read_only(&ExecutionContext::internal(db.database_identity()), |tx| {
db.get_all_tables(tx)
})
.with_read_only(Workload::Internal, |tx| db.get_all_tables(tx))
.expect("ids_to_name: database in a broken state?")
.iter()
.filter(|schema| is_table_visible(schema, &auth))
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/host/wasm_common/module_host_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl<T: WasmInstance> WasmModuleInstance<T> {

let op = ReducerOp {
id: reducer_id,
name: reducer_name,
name: reducer_name_arc.clone(),
caller_identity: &caller_identity,
caller_address: &caller_address,
timestamp,
Expand All @@ -444,7 +444,7 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
});
let _guard = WORKER_METRICS
.reducer_plus_query_duration
.with_label_values(&address, op.name)
.with_label_values(&address, reducer_name)
.with_timer(tx.timer);

let mut tx_slot = self.instance.instance_env().tx.clone();
Expand Down Expand Up @@ -576,7 +576,7 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
#[derive(Clone, Debug)]
pub struct ReducerOp<'a> {
pub id: ReducerId,
pub name: &'a str,
pub name: Arc<str>,
pub caller_identity: &'a Identity,
pub caller_address: &'a Address,
pub timestamp: Timestamp,
Expand All @@ -596,7 +596,7 @@ impl From<ReducerOp<'_>> for execution_context::ReducerContext {
}: ReducerOp<'_>,
) -> Self {
Self {
name: name.to_owned(),
name,
caller_identity: *caller_identity,
caller_address: *caller_address,
timestamp,
Expand Down
9 changes: 5 additions & 4 deletions crates/core/src/host/wasmtime/wasm_instance_env.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::too_many_arguments)]

use std::sync::Arc;
use std::time::Instant;

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

/// The last, including current, reducer to be executed by this environment.
reducer_name: String,
reducer_name: Arc<str>,
}

const CALL_REDUCER_ARGS_SOURCE: u32 = 1;
Expand All @@ -96,7 +97,7 @@ impl WasmInstanceEnv {
timing_spans: Default::default(),
reducer_start,
call_times: CallTimes::new(),
reducer_name: String::from(""),
reducer_name: "".into(),
}
}

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

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

self.reducer_start = Instant::now();
name.clone_into(&mut self.reducer_name);
self.reducer_name = name;

(args, errors)
}
Expand Down

0 comments on commit 6cc4313

Please sign in to comment.