mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-28 22:48:11 +08:00
Decrease graph compilation time significantly (#1368)
* Decrease compilation time significantly * Refactor reorder_ids method to improve performance
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user