Skip to content

Commit 84e4481

Browse files
authored
Run preprocessing on benchmarks and fix deadlock (#3230)
1 parent ffc7427 commit 84e4481

File tree

8 files changed

+14
-8
lines changed

8 files changed

+14
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-graph/interpreted-executor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ serde = { workspace = true }
2929
graph-craft = { workspace = true, features = ["loading"] }
3030
criterion = { workspace = true }
3131
iai-callgrind = { workspace = true }
32+
preprocessor = { workspace = true }
3233

3334
# Benchmarks
3435
[[bench]]

node-graph/interpreted-executor/benches/benchmark_util.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ use interpreted_executor::dynamic_executor::DynamicExecutor;
88
use interpreted_executor::util::wrap_network_in_scope;
99

1010
pub fn setup_network(name: &str) -> (DynamicExecutor, ProtoNetwork) {
11-
let network = load_from_name(name);
11+
let mut network = load_from_name(name);
1212
let editor_api = std::sync::Arc::new(EditorApi::default());
13+
println!("generating substitutions");
14+
let substitutions = preprocessor::generate_node_substitutions();
15+
println!("expanding network");
16+
preprocessor::expand_network(&mut network, &substitutions);
1317
let network = wrap_network_in_scope(network, editor_api);
1418
let proto_network = compile(network);
1519
let executor = block_on(DynamicExecutor::new(proto_network.clone())).unwrap();

node-graph/interpreted-executor/benches/run_cached.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn subsequent_evaluations(c: &mut Criterion) {
1010
bench_for_each_demo(&mut group, |name, g| {
1111
let (executor, _) = setup_network(name);
1212
g.bench_function(name, |b| {
13-
b.iter(|| futures::executor::block_on(executor.tree().eval_tagged_value(executor.output(), criterion::black_box(context))).unwrap())
13+
b.iter(|| futures::executor::block_on(executor.tree().eval_tagged_value(executor.output(), std::hint::black_box(context))).unwrap())
1414
});
1515
});
1616
group.finish();

node-graph/interpreted-executor/benches/run_demo_art_criterion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use criterion::measurement::Measurement;
2-
use criterion::{BenchmarkGroup, Criterion, black_box, criterion_group, criterion_main};
2+
use criterion::{BenchmarkGroup, Criterion, criterion_group, criterion_main};
33
use graph_craft::graphene_compiler::Executor;
44
use graph_craft::proto::ProtoNetwork;
55
use graph_craft::util::{DEMO_ART, compile, load_from_name};
@@ -16,7 +16,7 @@ fn update_executor<M: Measurement>(name: &str, c: &mut BenchmarkGroup<M>) {
1616
c.bench_function(name, |b| {
1717
b.iter_batched(
1818
|| (executor.clone(), proto_network.clone()),
19-
|(mut executor, network)| futures::executor::block_on(executor.update(black_box(network))),
19+
|(mut executor, network)| futures::executor::block_on(executor.update(std::hint::black_box(network))),
2020
criterion::BatchSize::SmallInput,
2121
)
2222
});

node-graph/interpreted-executor/benches/run_once.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn run_once(c: &mut Criterion) {
1111
g.bench_function(name, |b| {
1212
b.iter_batched(
1313
|| setup_network(name),
14-
|(executor, _)| futures::executor::block_on(executor.tree().eval_tagged_value(executor.output(), criterion::black_box(context))).unwrap(),
14+
|(executor, _)| futures::executor::block_on(executor.tree().eval_tagged_value(executor.output(), std::hint::black_box(context))).unwrap(),
1515
criterion::BatchSize::SmallInput,
1616
)
1717
});

node-graph/interpreted-executor/benches/update_executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn update_executor(c: &mut Criterion) {
1616
let executor = futures::executor::block_on(DynamicExecutor::new(empty)).unwrap();
1717
(executor, proto_network)
1818
},
19-
|(mut executor, network)| futures::executor::block_on(executor.update(criterion::black_box(network))),
19+
|(mut executor, network)| futures::executor::block_on(executor.update(std::hint::black_box(network))),
2020
criterion::BatchSize::SmallInput,
2121
)
2222
});

node-graph/preprocessor/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub fn expand_network(network: &mut NodeNetwork, substitutions: &HashMap<ProtoNo
2929

3030
pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNode> {
3131
let mut custom = HashMap::new();
32+
// We pre initialize the node registry here to avoid a deadlock
33+
let into_node_registry = &*interpreted_executor::node_registry::NODE_REGISTRY;
3234
let node_registry = graphene_core::registry::NODE_REGISTRY.lock().unwrap();
3335
for (id, metadata) in graphene_core::registry::NODE_METADATA.lock().unwrap().iter() {
3436
let id = id.clone();
@@ -54,8 +56,6 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
5456

5557
let identity_node = ops::identity::IDENTIFIER;
5658

57-
let into_node_registry = &interpreted_executor::node_registry::NODE_REGISTRY;
58-
5959
let mut generated_nodes = 0;
6060
let mut nodes: HashMap<_, _, _> = node_io_types
6161
.iter()

0 commit comments

Comments
 (0)