Require a node registry to compile so the layout pass always runs

This commit is contained in:
Dennis Kobert
2026-08-15 14:49:25 +00:00
parent 87200f3c2a
commit 99ce2ea565
12 changed files with 19 additions and 18 deletions

View File

@@ -74,6 +74,7 @@ mmap-io = { workspace = true }
[dev-dependencies]
# Workspace dependencies
graph-craft = { workspace = true, features = ["loading"] }
interpreted-executor = { workspace = true }
pretty_assertions = { workspace = true }
criterion = { workspace = true }
gungraun = { workspace = true }

View File

@@ -6,10 +6,11 @@ use graph_craft::util::DEMO_ART;
fn compile_to_proto(c: &mut Criterion) {
use graph_craft::util::{compile, load_from_name};
let mut c = c.benchmark_group("Compile Network cold");
let registry = &interpreted_executor::node_registry::NODE_REGISTRY;
for name in DEMO_ART {
let network = load_from_name(name);
c.bench_function(name, |b| b.iter_batched(|| network.clone(), |network| compile(black_box(network)), criterion::BatchSize::SmallInput));
c.bench_function(name, |b| b.iter_batched(|| network.clone(), |network| compile(black_box(network), registry), criterion::BatchSize::SmallInput));
}
}

View File

@@ -5,7 +5,7 @@ use gungraun::prelude::*;
#[library_benchmark]
#[benches::with_setup(args = ["isometric-fountain", "painted-dreams", "procedural-string-lights", "parametric-dunescape", "red-dress", "valley-of-spires"], setup = load_from_name)]
pub fn compile_to_proto(_input: NodeNetwork) {
std::hint::black_box(compile(_input));
std::hint::black_box(compile(_input, &interpreted_executor::node_registry::NODE_REGISTRY));
}
library_benchmark_group!(name = compile_group; benchmarks = compile_to_proto);

View File

@@ -5,7 +5,7 @@ use std::error::Error;
pub struct Compiler {}
impl Compiler {
pub fn compile<'r>(&self, mut network: NodeNetwork, registry: Option<&'r Registry>) -> impl Iterator<Item = Result<ProtoNetwork, String>> + 'r {
pub fn compile<'r>(&self, mut network: NodeNetwork, registry: &'r Registry) -> impl Iterator<Item = Result<ProtoNetwork, String>> + 'r {
network.resolve_scope_inputs();
network.generate_node_paths(&[]);
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
@@ -19,15 +19,13 @@ impl Compiler {
proto_networks.map(move |mut proto_network| {
proto_network.insert_context_nullification_nodes()?;
if let Some(registry) = registry {
let _ = proto_network.resolve_types(registry);
proto_network.compute_layouts();
}
let _ = proto_network.resolve_types(registry);
proto_network.compute_layouts();
proto_network.generate_stable_node_ids();
Ok(proto_network)
})
}
pub fn compile_single(&self, network: NodeNetwork, registry: Option<&Registry>) -> Result<ProtoNetwork, String> {
pub fn compile_single(&self, network: NodeNetwork, registry: &Registry) -> Result<ProtoNetwork, String> {
assert_eq!(network.exports.len(), 1, "Graph with multiple outputs not yet handled");
let Some(proto_network) = self.compile(network, registry).next() else {
return Err("Failed to convert graph into proto graph".to_string());

View File

@@ -1,6 +1,6 @@
use crate::document::NodeNetwork;
use crate::graphene_compiler::Compiler;
use crate::proto::ProtoNetwork;
use crate::proto::{ProtoNetwork, Registry};
pub fn load_network(document_string: &str) -> NodeNetwork {
let document: serde_json::Value = serde_json::from_str(document_string).expect("Failed to parse document");
@@ -8,9 +8,9 @@ pub fn load_network(document_string: &str) -> NodeNetwork {
serde_json::from_str::<NodeNetwork>(&document).expect("Failed to parse document")
}
pub fn compile(network: NodeNetwork) -> ProtoNetwork {
pub fn compile(network: NodeNetwork, registry: &Registry) -> ProtoNetwork {
let compiler = Compiler {};
compiler.compile_single(network, None).unwrap()
compiler.compile_single(network, registry).unwrap()
}
pub fn load_from_name(name: &str) -> NodeNetwork {