Skip to content
Merged
8 changes: 4 additions & 4 deletions src/DynamoCore/Engine/EngineController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,14 @@ internal void ReconcileTraceDataAndNotify()
var callsiteToOrphanMap = new Dictionary<Guid, List<string>>();
foreach (var cs in liveRunnerServices.RuntimeCore.RuntimeData.CallsiteCache.Values)
{
var orphanedSerializables = cs.GetOrphanedSerializables().ToList();
if (callsiteToOrphanMap.ContainsKey(cs.CallSiteID))
var orphanedSerializables = cs.GetOrphanedSerializables();
if (callsiteToOrphanMap.TryGetValue(cs.CallSiteID, out var serializablesForCallsite))
{
callsiteToOrphanMap[cs.CallSiteID].AddRange(orphanedSerializables);
serializablesForCallsite.AddRange(orphanedSerializables);
}
else
{
callsiteToOrphanMap.Add(cs.CallSiteID, orphanedSerializables);
callsiteToOrphanMap.Add(cs.CallSiteID, orphanedSerializables.ToList());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so orphanedSerializables is already a List<string> -

var result = new List<string>();
though it's declared here as an IList - I assume that this calls the List constructor passing in the existing list, have you verified there is any benefit to moving this ToList call around?

If it's really such a big performance impact you could probably change this data structure to be a dict of IList

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Graph/Workspaces/HomeWorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ internal IList<string> GetOrphanedSerializablesAndClearHistoricalTraceData()

if (Nodes.All(n => n.GUID != nodeGuid))
{
orphans.AddRange(nodeData.Value.SelectMany(CallSite.GetAllSerializablesFromSingleRunTraceData).ToList());
orphans.AddRange(nodeData.Value.SelectMany(CallSite.GetAllSerializablesFromSingleRunTraceData));
}
}

Expand Down
39 changes: 25 additions & 14 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,22 +1260,30 @@ private void EngineController_TraceReconcliationComplete(TraceReconciliationEven
// This dictionary gets redistributed into a dictionary keyed by the workspace id.

var workspaceOrphanMap = new Dictionary<Guid, List<string>>();
var nodeToWorkspaceMap = new Dictionary<Guid, WorkspaceModel>();

foreach (var ws in Workspaces.OfType<HomeWorkspaceModel>())
foreach (var maybeWs in Workspaces)
{
foreach (var node in maybeWs.Nodes)
nodeToWorkspaceMap[node.GUID] = maybeWs;

var ws = maybeWs as HomeWorkspaceModel;
if (ws == null)
continue;

// Get the orphaned serializables to this workspace
var wsOrphans = ws.GetOrphanedSerializablesAndClearHistoricalTraceData().ToList();
var wsOrphans = (List<string>)ws.GetOrphanedSerializablesAndClearHistoricalTraceData();

if (!wsOrphans.Any())
continue;

if (!workspaceOrphanMap.ContainsKey(ws.Guid))
if (workspaceOrphanMap.TryGetValue(ws.Guid, out var workspaceOrphans))
{
workspaceOrphanMap.Add(ws.Guid, wsOrphans);
workspaceOrphans.AddRange(wsOrphans);
}
else
{
workspaceOrphanMap[ws.Guid].AddRange(wsOrphans);
workspaceOrphanMap.Add(ws.Guid, wsOrphans);
}
}

Expand All @@ -1287,23 +1295,26 @@ private void EngineController_TraceReconcliationComplete(TraceReconciliationEven

// TODO: MAGN-7314
// Find the owning workspace for a node.
var nodeSpace =
Workspaces.FirstOrDefault(
ws =>
ws.Nodes.FirstOrDefault(n => n.GUID == nodeGuid)
!= null);
if (!nodeToWorkspaceMap.TryGetValue(nodeGuid, out var nodeSpace))
continue;

//var nodeSpace =
// Workspaces.FirstOrDefault(
// ws =>
// ws.Nodes.FirstOrDefault(n => n.GUID == nodeGuid)
// != null);

if (nodeSpace == null) continue;
//if (nodeSpace == null) continue;

// Add the node's orphaned serializables to the workspace
// orphan map.
if (workspaceOrphanMap.ContainsKey(nodeSpace.Guid))
if (workspaceOrphanMap.TryGetValue(nodeSpace.Guid, out var workspaceOrphans))
{
workspaceOrphanMap[nodeSpace.Guid].AddRange(kvp.Value);
workspaceOrphans.AddRange(kvp.Value);
}
else
{
workspaceOrphanMap.Add(nodeSpace.Guid, kvp.Value);
workspaceOrphanMap.Add(nodeSpace.Guid, kvp.Value.ToList());
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/Engine/ProtoCore/Lang/CallSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,20 @@ public bool Contains(string data)
public List<string> RecursiveGetNestedData()
{
List<string> ret = new List<string>();
RecursiveFillWithNestedData(ret);
return ret;
}

public void RecursiveFillWithNestedData(List<string> listToFill)
{
if (HasData)
ret.Add(Data);
listToFill.Add(Data);

if (HasNestedData)
{
foreach (SingleRunTraceData srtd in NestedData)
ret.AddRange(srtd.RecursiveGetNestedData());
srtd.RecursiveFillWithNestedData(listToFill);
}

return ret;
}
}

Expand Down Expand Up @@ -472,13 +475,11 @@ private static string CompressSerializedTraceData(string json)
/// </summary>
public IList<string> GetOrphanedSerializables()
{
var result = new List<string>();

if (!beforeFirstRunSerializables.Any())
return result;
if (beforeFirstRunSerializables.Count == 0)
return new List<string>();

var currentSerializables = traceData.SelectMany(td => td.RecursiveGetNestedData());
result.AddRange(beforeFirstRunSerializables.Where(hs => !currentSerializables.Contains(hs)).ToList());
var currentSerializables = traceData.SelectMany(td => td.RecursiveGetNestedData()).ToHashSet();
var result = beforeFirstRunSerializables.Where(hs => !currentSerializables.Contains(hs)).ToList();

// Clear the historical serializable to avoid
// them being used again.
Expand Down
20 changes: 3 additions & 17 deletions src/NodeServices/TraceSupport.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace DynamoServices
{
Expand Down Expand Up @@ -70,15 +69,9 @@ internal static void ClearAllKnownTLSKeys()
/// <returns></returns>
public static string GetTraceData(string key)
{
string data;
if (!LocalStorageSlot.TryGetValue(key, out data))
{
return null;
}
else
{
if (LocalStorageSlot.TryGetValue(key, out string data))
return data;
}
return null;
}

/// <summary>
Expand All @@ -88,14 +81,7 @@ public static string GetTraceData(string key)
/// <param name="value"></param>
public static void SetTraceData(string key, string value)
{
if (LocalStorageSlot.ContainsKey(key))
{
LocalStorageSlot[key] = value;
}
else
{
LocalStorageSlot.Add(key, value);
}
LocalStorageSlot[key] = value;
}
}
}
Loading