From 2f4e451b0aa8cfa3c88e1ec45b1b334715e3b4c1 Mon Sep 17 00:00:00 2001 From: Luke Church Date: Mon, 20 Apr 2015 00:51:11 +0100 Subject: [PATCH 1/2] Add task merging for graph updates --- .../Core/Threading/UpdateGraphAsyncTask.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/DynamoCore/Core/Threading/UpdateGraphAsyncTask.cs b/src/DynamoCore/Core/Threading/UpdateGraphAsyncTask.cs index febcabc1e7a..2083ca6f661 100644 --- a/src/DynamoCore/Core/Threading/UpdateGraphAsyncTask.cs +++ b/src/DynamoCore/Core/Threading/UpdateGraphAsyncTask.cs @@ -33,11 +33,11 @@ internal override TaskPriority Priority internal UpdateGraphAsyncTask(IScheduler scheduler, bool verboseLogging1) : base(scheduler) { - verboseLogging = verboseLogging; + this.verboseLogging = verboseLogging1; } /// - /// This method is called by codes that intent to start a graph update. + /// This method is called by code that intends to start a graph update. /// This method is called on the main thread where node collection in a /// WorkspaceModel can be safely accessed. /// @@ -102,6 +102,22 @@ protected override void HandleTaskCompletionCore() } } + protected override AsyncTask.TaskMergeInstruction CanMergeWithCore(AsyncTask otherTask) + { + var theOtherTask = otherTask as UpdateGraphAsyncTask; + if (theOtherTask == null) + return base.CanMergeWithCore(otherTask); + + // Comparing to another UpdateGraphAsyncTask, the one + // that gets scheduled more recently stay, while the earlier one + // gets dropped. If this task has a higher tick count, keep this. + // + if (ScheduledTime.TickCount > theOtherTask.ScheduledTime.TickCount) + return TaskMergeInstruction.KeepThis; + + return TaskMergeInstruction.KeepOther; // Otherwise, keep the other. + } + #endregion #region Public Class Properties From 63e800a3d82eb73f40e05544af1f7102de88356d Mon Sep 17 00:00:00 2001 From: Luke Church Date: Sat, 9 May 2015 04:20:49 -0700 Subject: [PATCH 2/2] Add merging based on the node IDs in the tasks --- .../Core/Threading/UpdateGraphAsyncTask.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/DynamoCore/Core/Threading/UpdateGraphAsyncTask.cs b/src/DynamoCore/Core/Threading/UpdateGraphAsyncTask.cs index 2083ca6f661..f7111e8ade9 100644 --- a/src/DynamoCore/Core/Threading/UpdateGraphAsyncTask.cs +++ b/src/DynamoCore/Core/Threading/UpdateGraphAsyncTask.cs @@ -62,8 +62,9 @@ internal bool Initialize(EngineController controller, WorkspaceModel workspace) graphSyncData = engineController.ComputeSyncData(workspace.Nodes, ModifiedNodes, verboseLogging); return graphSyncData != null; } - catch (Exception) + catch (Exception e) { + System.Diagnostics.Debug.WriteLine("UpgradeGraphAsyncTask saw: " + e.ToString()); return false; } } @@ -108,14 +109,24 @@ protected override AsyncTask.TaskMergeInstruction CanMergeWithCore(AsyncTask oth if (theOtherTask == null) return base.CanMergeWithCore(otherTask); - // Comparing to another UpdateGraphAsyncTask, the one - // that gets scheduled more recently stay, while the earlier one - // gets dropped. If this task has a higher tick count, keep this. - // - if (ScheduledTime.TickCount > theOtherTask.ScheduledTime.TickCount) + + // Comparing to another UpdateGraphAsyncTask, verify that they are updating + // a similar set of nodes + + // Other node is either equal or a superset of this task + if (ModifiedNodes.All(x => theOtherTask.ModifiedNodes.Contains(x))) + { + return TaskMergeInstruction.KeepOther; + } + + // This node is a superset of the other + if (theOtherTask.ModifiedNodes.All(x => ModifiedNodes.Contains(x))) + { return TaskMergeInstruction.KeepThis; + } - return TaskMergeInstruction.KeepOther; // Otherwise, keep the other. + // They're different, keep both + return TaskMergeInstruction.KeepBoth; } #endregion