Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory/perf improvements #367

Merged
merged 6 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ exclude = [
"examples/cli/cli-maker",
]

[profile.release-with-debug]
inherits = "release"
debug = true

[workspace.dependencies]
#
# crates/wick
Expand Down
6 changes: 5 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ install:
@echo "Use 'just install-debug' to build debug version."
cargo install --path crates/bins/wick

# Build wick binary with debug symbols and additional output
# Build an optimized wick binary with debug symbols
install-debug:
cargo install --profile=release-with-debug --path crates/bins/wick

# Build wick binary with debug symbols and additional output
install-dev:
cargo install --path crates/bins/wick --debug

# Build wasm binaries that wick tests depend on
Expand Down
3 changes: 2 additions & 1 deletion crates/bins/wick/src/commands/new/component/wasmrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use wick_config::config::{
OperationDefinitionBuilder,
WasmComponentImplementationBuilder,
};
use wick_config::AssetReference;
use wick_interface_types::{Field, StructDefinition, Type, TypeDefinition};

use crate::io::File;
Expand Down Expand Up @@ -52,7 +53,7 @@ pub(crate) async fn handle(
config.set_metadata(crate::commands::new::generic_metadata("New WebAssembly wick component"));

let component = WasmComponentImplementationBuilder::default()
.reference(config::AssetReference::new(format!("./build/{}", &name)))
.reference(AssetReference::new(format!("./build/{}", &name)))
.operations([
OperationDefinitionBuilder::default()
.name("operation_name".to_owned())
Expand Down
17 changes: 4 additions & 13 deletions crates/bins/wick/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,15 @@ async fn async_start() -> Result<(GlobalOptions, StructuredOutput), (GlobalOptio
// Initialize the global logger
let logger = wick_logger::init(&logger_opts);

let res = tokio::spawn(async_main(cli, settings)).await;
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
let res = async_main(cli, settings).await;

let res = match res {
Ok(Ok(output)) => {
Ok(output) => {
debug!("Done");
Ok((options, output))
}
Ok(Err(e)) => {
error!("Error: {}", e);
Err((options, anyhow!("{}", e)))
}
Err(e) => {
error!("Internal Error: {}", e);
error!("Error: {}", e);
Err((options, anyhow!("{}", e)))
}
};
Expand Down Expand Up @@ -269,11 +265,6 @@ async fn async_main(cli: Cli, settings: wick_settings::Settings) -> Result<Struc
mod test {
use super::*;

#[test]
fn cli_tests() {
trycmd::TestCases::new().case("tests/cmd/*.trycmd");
}

#[test]
fn verify_app() {
use clap::CommandFactory;
Expand Down
3 changes: 2 additions & 1 deletion crates/bins/wick/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::collections::HashMap;
use futures::StreamExt;
use serde_json::Value;
use wick_component_cli::options::DefaultCliOptions;
use wick_config::config::{AssetReference, ComponentConfiguration, HttpConfigBuilder, LiquidJsonConfig};
use wick_config::config::{ComponentConfiguration, HttpConfigBuilder, LiquidJsonConfig};
use wick_config::AssetReference;
use wick_packet::{Packet, PacketStream, RuntimeConfig};

pub(crate) fn merge_config(
Expand Down
2 changes: 1 addition & 1 deletion crates/bins/wick/tests/run/integration/postgres.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ stdout = """

cli:db: in WebAssembly CLI component
cli:db: looking up user with id: 1.
cli:db: calling provided component operation at URL: wick://test-cli-with-db/=>wick://MYDB/get_user
cli:db: calling provided component operation at URL: wick://cli/=>wick://MYDB/get_user
cli:db: call succeeded, waiting for response...
cli:db: row data: {"name":"Test User"}
cli:db: response stream ended.
Expand Down
4 changes: 2 additions & 2 deletions crates/wick/flow-graph-interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::graph::types::*;
use crate::interpreter::channel::InterpreterChannel;
use crate::interpreter::components::component_component::ComponentComponent;
use crate::interpreter::components::null_component::NullComponent;
use crate::interpreter::components::schematic_component::SelfComponent;
use crate::interpreter::components::self_component::SelfComponent;
use crate::interpreter::executor::error::ExecutionError;
use crate::{NamespaceHandler, Observer, SharedHandler};

Expand All @@ -37,7 +37,7 @@ pub struct Interpreter {
event_loop: EventLoop,
signature: ComponentSignature,
components: Arc<HandlerMap>,
self_component: Arc<SelfComponent>,
self_component: SelfComponent,
dispatcher: InterpreterDispatchChannel,
namespace: Option<String>,
callback: Arc<RuntimeCallback>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) mod component_component;
pub(crate) mod core_component;
pub(crate) mod internal_component;
pub(crate) mod null_component;
pub(crate) mod schematic_component;
pub(crate) mod self_component;

use flow_component::Component;
use wick_interface_types::ComponentSignature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use wick_packet::{
};

use crate::graph::types::{Network, Schematic};
use crate::interpreter::components::schematic_component::SelfComponent;
use crate::interpreter::components::self_component::SelfComponent;
use crate::utils::path_to_entity;
use crate::{BoxFuture, HandlerMap};
pub(crate) struct Op {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use flow_component::{Component, ComponentError, RuntimeCallback};
use parking_lot::Mutex;
use tracing_futures::Instrument;
use wick_interface_types::ComponentSignature;
use wick_packet::{Invocation, PacketStream, RuntimeConfig};
Expand All @@ -19,23 +18,20 @@ pub(crate) enum Error {
}

#[derive(Debug)]
pub(crate) struct SelfComponent {
pub(crate) struct InnerSelf {
signature: ComponentSignature,
schematics: Arc<Vec<SchematicExecutor>>,
components: Arc<HandlerMap>,
self_component: Mutex<Option<Arc<Self>>>,
config: Option<RuntimeConfig>,
}

impl SelfComponent {
pub(crate) const ID: &str = "self";

impl InnerSelf {
pub(crate) fn new(
components: Arc<HandlerMap>,
state: &ProgramState,
config: Option<RuntimeConfig>,
dispatcher: &InterpreterDispatchChannel,
) -> Arc<Self> {
) -> Self {
let schematics: Arc<Vec<SchematicExecutor>> = Arc::new(
state
.network
Expand All @@ -44,27 +40,34 @@ impl SelfComponent {
.map(|s| SchematicExecutor::new(s.clone(), dispatcher.clone()))
.collect(),
);
let signature = state.components.get(Self::ID).unwrap().clone();
let component = Arc::new(Self {
let signature = state.components.get(SelfComponent::ID).unwrap().clone();
Self {
signature,
schematics,
self_component: Mutex::new(None),
components,
config,
});
component.update_self_component();
component
}
}
}

fn update_self_component(self: &Arc<Self>) {
let mut lock = self.self_component.lock();
lock.replace(self.clone());
drop(lock);
}
#[derive(Debug, Clone)]
pub(crate) struct SelfComponent {
inner: Arc<InnerSelf>,
}

fn clone_self_component(&self) -> Arc<Self> {
let lock = self.self_component.lock();
lock.clone().unwrap()
impl SelfComponent {
pub(crate) const ID: &str = "self";

pub(crate) fn new(
components: Arc<HandlerMap>,
state: &ProgramState,
config: Option<RuntimeConfig>,
dispatcher: &InterpreterDispatchChannel,
) -> Self {
let inner_self = InnerSelf::new(components, state, config, dispatcher);
Self {
inner: Arc::new(inner_self),
}
}
}

Expand All @@ -78,18 +81,19 @@ impl Component for SelfComponent {
invocation.trace(|| debug!(target = %invocation.target, namespace = Self::ID));

let mut op_config = LiquidOperationConfig::new_value(config);
op_config.set_root(self.config.clone());
op_config.set_root(self.inner.config.clone());

let operation = invocation.target.operation_id().to_owned();
let fut = self
.inner
.schematics
.iter()
.find(|s| s.name() == operation)
.map(|s| {
s.invoke(
invocation,
self.components.clone(),
self.clone_self_component(),
self.inner.components.clone(),
self.clone(),
op_config,
callback,
)
Expand All @@ -106,6 +110,6 @@ impl Component for SelfComponent {
}

fn signature(&self) -> &ComponentSignature {
&self.signature
&self.inner.signature
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::sync::Arc;

use flow_component::{Component, RuntimeCallback};
use flow_component::RuntimeCallback;
use seeded_random::Seed;
use wick_packet::{Invocation, PacketStream};

use self::error::ExecutionError;
use self::transaction::Transaction;
use super::channel::InterpreterDispatchChannel;
use super::components::self_component::SelfComponent;
use crate::graph::types::*;
use crate::graph::LiquidOperationConfig;
use crate::HandlerMap;
Expand Down Expand Up @@ -41,7 +42,7 @@ impl SchematicExecutor {
&self,
invocation: Invocation,
components: Arc<HandlerMap>,
self_component: Arc<dyn Component + Send + Sync>,
self_component: SelfComponent,
config: LiquidOperationConfig,
callback: Arc<RuntimeCallback>,
) -> Result<PacketStream> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::{Instant, SystemTime};

use flow_component::{RuntimeCallback, SharedComponent};
use flow_component::RuntimeCallback;
use flow_graph::{NodeIndex, PortReference, SCHEMATIC_OUTPUT_INDEX};
use futures::StreamExt;
use parking_lot::Mutex;
Expand All @@ -16,6 +16,7 @@ use super::error::ExecutionError;
use crate::graph::types::*;
use crate::graph::LiquidOperationConfig;
use crate::interpreter::channel::InterpreterDispatchChannel;
use crate::interpreter::components::self_component::SelfComponent;
use crate::interpreter::error::StateError;
use crate::interpreter::executor::transaction::operation::port::PortStatus;
use crate::{HandlerMap, InterpreterOptions};
Expand Down Expand Up @@ -64,7 +65,7 @@ impl Transaction {
mut invocation: Invocation,
channel: InterpreterDispatchChannel,
components: &Arc<HandlerMap>,
self_component: &SharedComponent,
self_component: &SelfComponent,
callback: Arc<RuntimeCallback>,
config: LiquidOperationConfig,
seed: Seed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use self::port::{InputPorts, OutputPorts, PortStatus};
use crate::graph::types::*;
use crate::graph::{LiquidOperationConfig, Reference};
use crate::interpreter::channel::InterpreterDispatchChannel;
use crate::interpreter::components::schematic_component::SelfComponent;
use crate::interpreter::components::self_component::SelfComponent;
use crate::interpreter::error::StateError;
use crate::interpreter::executor::error::ExecutionError;
use crate::{HandlerMap, InterpreterOptions};
Expand All @@ -36,7 +36,7 @@ pub(crate) struct InstanceHandler {
schematic: Arc<Schematic>,
pending: AtomicU32,
components: Arc<HandlerMap>,
self_component: Arc<dyn Component + Send + Sync>,
self_component: SelfComponent,
}

impl std::fmt::Debug for InstanceHandler {
Expand All @@ -62,7 +62,7 @@ impl InstanceHandler {
schematic: Arc<Schematic>,
operation: &Operation,
components: Arc<HandlerMap>,
self_component: Arc<dyn Component + Send + Sync>,
self_component: SelfComponent,
) -> Self {
let inputs = operation.inputs().to_vec();
let outputs = operation.outputs().to_vec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use wick_interface_types::{ComponentSignature, Field, OperationSignature, Type};

use crate::error::ValidationError;
use crate::graph::types::*;
use crate::interpreter::components::schematic_component::SelfComponent;
use crate::interpreter::components::self_component::SelfComponent;

pub(crate) mod validator;
use super::components::{reconcile_op_id, ComponentMap};
Expand Down
Loading