Make the node graph use a document node's default type (#1965)

* Use document node default type

* Refactor getting input

* Clippy

* Fix missing continue

* Fix CI
This commit is contained in:
James Lindsay 2024-09-13 09:42:26 +01:00 committed by GitHub
parent 507210b961
commit 514582fd8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 278 additions and 191 deletions

View file

@ -1,6 +1,5 @@
use graph_craft::document::NodeNetwork;
use graph_craft::graphene_compiler::Compiler;
use graph_craft::proto::ProtoNetwork;
#[cfg(any(feature = "criterion", feature = "iai"))]
use graph_craft::{document::NodeNetwork, graphene_compiler::Compiler, proto::ProtoNetwork};
#[cfg(feature = "criterion")]
use criterion::{black_box, criterion_group, criterion_main, Criterion};
@ -8,11 +7,13 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
#[cfg(all(not(feature = "criterion"), feature = "iai"))]
use iai_callgrind::{black_box, library_benchmark, library_benchmark_group, main};
#[cfg(any(feature = "criterion", feature = "iai"))]
fn load_network(document_string: &str) -> NodeNetwork {
let document: serde_json::Value = serde_json::from_str(document_string).expect("Failed to parse document");
serde_json::from_value::<NodeNetwork>(document["network_interface"]["network"].clone()).expect("Failed to parse document")
}
#[cfg(any(feature = "criterion", feature = "iai"))]
fn compile(network: NodeNetwork) -> ProtoNetwork {
let compiler = Compiler {};
compiler.compile_single(network).unwrap()
@ -41,6 +42,7 @@ fn compile_to_proto(c: &mut Criterion) {
#[cfg_attr(all(feature = "iai", not(feature = "criterion")), library_benchmark)]
#[cfg_attr(all(feature = "iai", not(feature="criterion")), benches::with_setup(args = ["isometric-fountain", "painted-dreams", "procedural-string-lights", "red-dress", "valley-of-spires"], setup = load_from_name))]
#[cfg(all(not(feature = "criterion"), feature = "iai"))]
pub fn iai_compile_to_proto(input: NodeNetwork) {
black_box(compile(input));
}
@ -56,3 +58,6 @@ library_benchmark_group!(name = compile_group; benchmarks = iai_compile_to_proto
#[cfg(all(not(feature = "criterion"), feature = "iai"))]
main!(library_benchmark_groups = compile_group);
#[cfg(all(not(feature = "criterion"), not(feature = "iai")))]
fn main() {}