Decrease graph compilation time significantly (#1368)

* Decrease compilation time significantly

* Refactor reorder_ids method to improve performance
This commit is contained in:
Dennis Kobert
2023-08-06 21:36:44 +02:00
committed by GitHub
parent c653fe9579
commit 3262f637d1
13 changed files with 125 additions and 112 deletions
@@ -8,7 +8,7 @@ use crate::proto::{LocalFuture, ProtoNetwork};
pub struct Compiler {}
impl Compiler {
pub fn compile(&self, mut network: NodeNetwork, resolve_inputs: bool) -> impl Iterator<Item = ProtoNetwork> {
pub fn compile(&self, mut network: NodeNetwork) -> impl Iterator<Item = ProtoNetwork> {
println!("flattening");
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
for id in node_ids {
@@ -18,18 +18,14 @@ impl Compiler {
network.remove_dead_nodes();
let proto_networks = network.into_proto_networks();
proto_networks.map(move |mut proto_network| {
if resolve_inputs {
println!("resolving inputs");
proto_network.resolve_inputs();
}
proto_network.reorder_ids();
proto_network.resolve_inputs();
proto_network.generate_stable_node_ids();
proto_network
})
}
pub fn compile_single(&self, network: NodeNetwork, resolve_inputs: bool) -> Result<ProtoNetwork, String> {
pub fn compile_single(&self, network: NodeNetwork) -> Result<ProtoNetwork, String> {
assert_eq!(network.outputs.len(), 1, "Graph with multiple outputs not yet handled");
let Some(proto_network) = self.compile(network, resolve_inputs).next() else {
let Some(proto_network) = self.compile(network).next() else {
return Err("Failed to convert graph into proto graph".to_string());
};
Ok(proto_network)