Skip to content

Commit 8f47485

Browse files
committed
Only update thumbnails if the graph has changed
1 parent c607e6e commit 8f47485

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

editor/src/node_graph_executor.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct NodeRuntime {
5858
pub(crate) click_targets: HashMap<NodeId, Vec<ClickTarget>>,
5959
pub(crate) transforms: HashMap<NodeId, DAffine2>,
6060
pub(crate) upstream_transforms: HashMap<NodeId, DAffine2>,
61-
compile_cache: Option<(u64, Vec<Vec<NodeId>>)>,
61+
graph_hash: Option<u64>,
6262
canvas_cache: HashMap<Vec<LayerId>, SurfaceId>,
6363
}
6464

@@ -126,7 +126,7 @@ impl NodeRuntime {
126126
canvas_cache: HashMap::new(),
127127
click_targets: HashMap::new(),
128128
transforms: HashMap::new(),
129-
compile_cache: None,
129+
graph_hash: None,
130130
upstream_transforms: HashMap::new(),
131131
}
132132
}
@@ -154,8 +154,10 @@ impl NodeRuntime {
154154
}) => {
155155
let (result, monitor_nodes) = self.execute_network(&path, graph, transform, viewport_resolution).await;
156156
let mut responses = VecDeque::new();
157-
self.update_thumbnails(&path, &monitor_nodes, &mut responses);
158-
self.update_upstream_transforms(&monitor_nodes);
157+
if let Some(ref monitor_nodes) = monitor_nodes {
158+
self.update_thumbnails(&path, &monitor_nodes, &mut responses);
159+
self.update_upstream_transforms(&monitor_nodes);
160+
}
159161
let response = GenerationResponse {
160162
generation_id,
161163
result,
@@ -172,7 +174,7 @@ impl NodeRuntime {
172174
}
173175
}
174176

175-
async fn execute_network<'a>(&'a mut self, path: &[LayerId], graph: NodeNetwork, transform: DAffine2, viewport_resolution: UVec2) -> (Result<TaggedValue, String>, MonitorNodes) {
177+
async fn execute_network<'a>(&'a mut self, path: &[LayerId], graph: NodeNetwork, transform: DAffine2, viewport_resolution: UVec2) -> (Result<TaggedValue, String>, Option<MonitorNodes>) {
176178
if self.wasm_io.is_none() {
177179
self.wasm_io = Some(WasmApplicationIo::new().await);
178180
}
@@ -204,12 +206,15 @@ impl NodeRuntime {
204206
let font_hash_code = graph_input_hash.finish();
205207
graph.hash(&mut graph_input_hash);
206208
let hash_code = graph_input_hash.finish();
209+
log::debug!("Hash code: {}", hash_code);
207210

208-
if self.compile_cache.as_ref().map(|(hash, _)| *hash) != Some(hash_code) {
209-
self.compile_cache = None;
211+
if self.graph_hash != Some(hash_code) {
212+
self.graph_hash = None;
210213
}
211214

212-
if self.compile_cache.is_none() {
215+
let mut cached_monitor_nodes = None;
216+
217+
if self.graph_hash.is_none() {
213218
let scoped_network = wrap_network_in_scope(graph, font_hash_code);
214219

215220
let monitor_nodes = scoped_network
@@ -223,18 +228,18 @@ impl NodeRuntime {
223228
let c = Compiler {};
224229
let proto_network = match c.compile_single(scoped_network) {
225230
Ok(network) => network,
226-
Err(e) => return (Err(e), monitor_nodes),
231+
Err(e) => return (Err(e), Some(monitor_nodes)),
227232
};
228233

229234
assert_ne!(proto_network.nodes.len(), 0, "No protonodes exist?");
230235
if let Err(e) = self.executor.update(proto_network).await {
231236
error!("Failed to update executor:\n{e}");
232-
return (Err(e), monitor_nodes);
237+
return (Err(e), Some(monitor_nodes));
233238
}
234239

235-
self.compile_cache = Some((hash_code, monitor_nodes));
240+
cached_monitor_nodes = Some(monitor_nodes);
241+
self.graph_hash = Some(hash_code);
236242
}
237-
let (hash_code, monitor_nodes) = self.compile_cache.as_ref().unwrap();
238243

239244
use graph_craft::graphene_compiler::Executor;
240245

@@ -246,7 +251,7 @@ impl NodeRuntime {
246251
};
247252
let result = match result {
248253
Ok(value) => value,
249-
Err(e) => return (Err(e), monitor_nodes.clone()),
254+
Err(e) => return (Err(e), cached_monitor_nodes),
250255
};
251256

252257
if let TaggedValue::SurfaceFrame(SurfaceFrame { surface_id, transform: _ }) = result {
@@ -259,7 +264,7 @@ impl NodeRuntime {
259264
}
260265
}
261266
}
262-
(Ok(result), monitor_nodes.clone())
267+
(Ok(result), cached_monitor_nodes)
263268
}
264269

265270
/// Recomputes the thumbnails for the layers in the graph, modifying the state and updating the UI.

0 commit comments

Comments
 (0)