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

Add a profiling action to CI which comments on PRs with notable demo art performance variances #1925

Merged
merged 17 commits into from
Aug 15, 2024
Merged
Prev Previous commit
Next Next commit
Fix rebase regression
TrueDoctor committed Aug 15, 2024
commit fa3ed7ab78148ec7982d1ace72176b17b4afe225
36 changes: 19 additions & 17 deletions node-graph/graph-craft/benches/compile_demo_art.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
use graph_craft::document::NodeNetwork;
use graph_craft::graphene_compiler::Compiler;
use graph_craft::proto::ProtoNetwork;
use std::path::PathBuf;

#[cfg(all(feature = "criterion", not(feature = "iai")))]
#[cfg(feature = "criterion")]
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};

pub fn load_network(document_string: &str) -> NodeNetwork {
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")
}

pub fn compile(network: NodeNetwork) -> ProtoNetwork {
fn compile(network: NodeNetwork) -> ProtoNetwork {
let compiler = Compiler {};
compiler.compile_single(network).unwrap()
}

pub fn bench_compile(path: PathBuf) {
let content = std::fs::read(&path).expect("failed to read file");
#[cfg(all(not(feature = "criterion"), feature = "iai"))]
fn load_from_name(name: &str) -> NodeNetwork {
let content = std::fs::read(&format!("../../demo-artwork/{name}.graphite")).expect("failed to read file");
let network = load_network(std::str::from_utf8(&content).unwrap());
let content = std::str::from_utf8(&content).unwrap();
black_box(compile(black_box(network)));
load_network(content)
}

#[cfg(all(feature = "criterion", not(feature = "iai")))]
#[cfg(feature = "criterion")]
fn compile_to_proto(c: &mut Criterion) {
let artworks = glob::glob("../../demo-artwork/*.graphite").expect("failed to read glob pattern");
for path in artworks {
let Ok(path) = path else { continue };
let name = path.file_stem().unwrap().to_str().unwrap();
c.bench_function(name, |b| b.iter(|| bench_compile(path.clone())));
let content = std::fs::read(&path).expect("failed to read file");
let network = load_network(std::str::from_utf8(&content).unwrap());
c.bench_function(name, |b| b.iter_batched(|| network.clone(), |network| compile(black_box(network)), criterion::BatchSize::SmallInput));
}
}

#[cfg_attr(feature = "iai", library_benchmark)]
fn iai_compile_to_proto() {
let artworks = glob::glob("../../demo-artwork/*.graphite").expect("failed to read glob pattern");
for path in artworks {
let Ok(path) = path else { continue };
bench_compile(path);
}
#[cfg(all(not(feature = "criterion"), feature = "iai"))]
#[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))]
fn iai_compile_to_proto(input: NodeNetwork) {
black_box(compile(input));
}

#[cfg(all(feature = "criterion", not(feature = "iai")))]
#[cfg(feature = "criterion")]
criterion_group!(benches, compile_to_proto);

#[cfg(all(feature = "criterion", not(feature = "iai")))]
#[cfg(feature = "criterion")]
criterion_main!(benches);

#[cfg(all(not(feature = "criterion"), feature = "iai"))]