Run preprocessing on benchmarks and fix deadlock (#3230)

This commit is contained in:
Dennis Kobert 2025-09-27 12:36:29 +02:00 committed by GitHub
parent ffc74273cc
commit 84e44810d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 14 additions and 8 deletions

1
Cargo.lock generated
View File

@ -2887,6 +2887,7 @@ dependencies = [
"iai-callgrind", "iai-callgrind",
"log", "log",
"once_cell", "once_cell",
"preprocessor",
"serde", "serde",
"wgpu-executor", "wgpu-executor",
] ]

View File

@ -29,6 +29,7 @@ serde = { workspace = true }
graph-craft = { workspace = true, features = ["loading"] } graph-craft = { workspace = true, features = ["loading"] }
criterion = { workspace = true } criterion = { workspace = true }
iai-callgrind = { workspace = true } iai-callgrind = { workspace = true }
preprocessor = { workspace = true }
# Benchmarks # Benchmarks
[[bench]] [[bench]]

View File

@ -8,8 +8,12 @@ use interpreted_executor::dynamic_executor::DynamicExecutor;
use interpreted_executor::util::wrap_network_in_scope; use interpreted_executor::util::wrap_network_in_scope;
pub fn setup_network(name: &str) -> (DynamicExecutor, ProtoNetwork) { pub fn setup_network(name: &str) -> (DynamicExecutor, ProtoNetwork) {
let network = load_from_name(name); let mut network = load_from_name(name);
let editor_api = std::sync::Arc::new(EditorApi::default()); let editor_api = std::sync::Arc::new(EditorApi::default());
println!("generating substitutions");
let substitutions = preprocessor::generate_node_substitutions();
println!("expanding network");
preprocessor::expand_network(&mut network, &substitutions);
let network = wrap_network_in_scope(network, editor_api); let network = wrap_network_in_scope(network, editor_api);
let proto_network = compile(network); let proto_network = compile(network);
let executor = block_on(DynamicExecutor::new(proto_network.clone())).unwrap(); let executor = block_on(DynamicExecutor::new(proto_network.clone())).unwrap();

View File

@ -10,7 +10,7 @@ fn subsequent_evaluations(c: &mut Criterion) {
bench_for_each_demo(&mut group, |name, g| { bench_for_each_demo(&mut group, |name, g| {
let (executor, _) = setup_network(name); let (executor, _) = setup_network(name);
g.bench_function(name, |b| { g.bench_function(name, |b| {
b.iter(|| futures::executor::block_on(executor.tree().eval_tagged_value(executor.output(), criterion::black_box(context))).unwrap()) b.iter(|| futures::executor::block_on(executor.tree().eval_tagged_value(executor.output(), std::hint::black_box(context))).unwrap())
}); });
}); });
group.finish(); group.finish();

View File

@ -1,5 +1,5 @@
use criterion::measurement::Measurement; use criterion::measurement::Measurement;
use criterion::{BenchmarkGroup, Criterion, black_box, criterion_group, criterion_main}; use criterion::{BenchmarkGroup, Criterion, criterion_group, criterion_main};
use graph_craft::graphene_compiler::Executor; use graph_craft::graphene_compiler::Executor;
use graph_craft::proto::ProtoNetwork; use graph_craft::proto::ProtoNetwork;
use graph_craft::util::{DEMO_ART, compile, load_from_name}; 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>) {
c.bench_function(name, |b| { c.bench_function(name, |b| {
b.iter_batched( b.iter_batched(
|| (executor.clone(), proto_network.clone()), || (executor.clone(), proto_network.clone()),
|(mut executor, network)| futures::executor::block_on(executor.update(black_box(network))), |(mut executor, network)| futures::executor::block_on(executor.update(std::hint::black_box(network))),
criterion::BatchSize::SmallInput, criterion::BatchSize::SmallInput,
) )
}); });

View File

@ -11,7 +11,7 @@ fn run_once(c: &mut Criterion) {
g.bench_function(name, |b| { g.bench_function(name, |b| {
b.iter_batched( b.iter_batched(
|| setup_network(name), || setup_network(name),
|(executor, _)| futures::executor::block_on(executor.tree().eval_tagged_value(executor.output(), criterion::black_box(context))).unwrap(), |(executor, _)| futures::executor::block_on(executor.tree().eval_tagged_value(executor.output(), std::hint::black_box(context))).unwrap(),
criterion::BatchSize::SmallInput, criterion::BatchSize::SmallInput,
) )
}); });

View File

@ -16,7 +16,7 @@ fn update_executor(c: &mut Criterion) {
let executor = futures::executor::block_on(DynamicExecutor::new(empty)).unwrap(); let executor = futures::executor::block_on(DynamicExecutor::new(empty)).unwrap();
(executor, proto_network) (executor, proto_network)
}, },
|(mut executor, network)| futures::executor::block_on(executor.update(criterion::black_box(network))), |(mut executor, network)| futures::executor::block_on(executor.update(std::hint::black_box(network))),
criterion::BatchSize::SmallInput, criterion::BatchSize::SmallInput,
) )
}); });

View File

@ -29,6 +29,8 @@ pub fn expand_network(network: &mut NodeNetwork, substitutions: &HashMap<ProtoNo
pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNode> { pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNode> {
let mut custom = HashMap::new(); let mut custom = HashMap::new();
// We pre initialize the node registry here to avoid a deadlock
let into_node_registry = &*interpreted_executor::node_registry::NODE_REGISTRY;
let node_registry = graphene_core::registry::NODE_REGISTRY.lock().unwrap(); let node_registry = graphene_core::registry::NODE_REGISTRY.lock().unwrap();
for (id, metadata) in graphene_core::registry::NODE_METADATA.lock().unwrap().iter() { for (id, metadata) in graphene_core::registry::NODE_METADATA.lock().unwrap().iter() {
let id = id.clone(); let id = id.clone();
@ -54,8 +56,6 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
let identity_node = ops::identity::IDENTIFIER; let identity_node = ops::identity::IDENTIFIER;
let into_node_registry = &interpreted_executor::node_registry::NODE_REGISTRY;
let mut generated_nodes = 0; let mut generated_nodes = 0;
let mut nodes: HashMap<_, _, _> = node_io_types let mut nodes: HashMap<_, _, _> = node_io_types
.iter() .iter()