Skip to content

Commit

Permalink
DYN-6449 Graph Loading Performance Improving
Browse files Browse the repository at this point in the history
Using Jetbrains dotTrace I noticed that creating the NodeView for Watch nodes was taking too much time when loading the Graph (due that was creating the PreviewControl), then due that Watch nodes doesn't have Preview I've added code for preventing the creation of the PreviewControl, this improved the Graph loading time.
Also I've noticed that the call nodeView.UpdateLayout() was consuming loading time so I've modified the code in a way that the method call will be executed asynchronous in background.
  • Loading branch information
RobertGlobant20 committed Feb 8, 2024
1 parent 3893c85 commit 4276e2c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Windows.Controls;
using System.Windows.Threading;
using Dynamo.Controls;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Workspaces;
Expand Down Expand Up @@ -60,7 +62,10 @@ public void CustomizeView(Function function, NodeView nodeView)
publishCustomNodeItem.Command = nodeView.ViewModel.DynamoViewModel.PublishSelectedNodesCommand;
publishCustomNodeItem.CommandParameter = functionNodeModel;

nodeView.UpdateLayout();
nodeView.Dispatcher.BeginInvoke(new Action(() =>
{
nodeView.UpdateLayout();
}), DispatcherPriority.Background);
}

private void EditCustomNodeProperties()
Expand Down Expand Up @@ -136,4 +141,4 @@ public void Dispose()

}
}
}
}
8 changes: 7 additions & 1 deletion src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
Expand Down Expand Up @@ -551,6 +551,9 @@ private void OnNodeViewMouseLeave(object sender, MouseEventArgs e)
{
ViewModel.ZIndex = oldZIndex;

//Watch nodes doesn't have Preview so we should avoid to use any method/property in PreviewControl class due that Preview is created automatically
if (ViewModel.NodeModel != null && ViewModel.NodeModel is CoreNodeModels.Watch) return;

// If mouse in over node/preview control or preview control is pined, we can not hide preview control.
if (IsMouseOver || PreviewControl.IsMouseOver || PreviewControl.StaysOpen || IsMouseInsidePreview(e) ||
(Mouse.Captured is DragCanvas && IsMouseInsideNodeOrPreview(e.GetPosition(this)))) return;
Expand Down Expand Up @@ -731,6 +734,9 @@ internal void TogglePreviewControlAllowance()
{
previewEnabled = !previewEnabled;

//Watch nodes doesn't have Preview so we should avoid to use any method/property in PreviewControl class due that Preview is created automatically
if (ViewModel.NodeModel != null && ViewModel.NodeModel is CoreNodeModels.Watch) return;

if (previewEnabled == false && !PreviewControl.StaysOpen)
{
if (PreviewControl.IsExpanded)
Expand Down
8 changes: 6 additions & 2 deletions src/Libraries/PythonNodeModelsWpf/PythonNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Threading;
using Dynamo.Configuration;
using Dynamo.Controls;
using Dynamo.Graph.Nodes;
Expand Down Expand Up @@ -99,8 +100,11 @@ public void CustomizeView(PythonNode nodeModel, NodeView nodeView)
PythonEngineManager.Instance.AvailableEngines.CollectionChanged += PythonEnginesChanged;

nodeView.MainContextMenu.Items.Add(learnMoreItem);

nodeView.UpdateLayout();
nodeView.Dispatcher.BeginInvoke(new Action( () =>
{
nodeView.UpdateLayout();
}), DispatcherPriority.Background);


nodeView.MouseDown += View_MouseDown;
nodeModel.DeletionStarted += NodeModel_DeletionStarted;
Expand Down

0 comments on commit 4276e2c

Please sign in to comment.