Skip to content

Commit

Permalink
DYN-4229 GraphicDataProvider optimization for repeated calls to get s…
Browse files Browse the repository at this point in the history
…imilar object types for tessellation (#11920)

* Add short circuit to prevent re-alocation of objects for repeated calls to the GetCLRObject

* Update comment

* Do not cache stackvalue.  Does not effect Marshaller object

* Add clear method

Co-authored-by: Craig Long <[email protected]>
  • Loading branch information
saintentropy and saintentropy authored May 23, 2022
1 parent 6901cb0 commit 473582b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Engine/ProtoCore/Reflection/GraphicDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,17 @@ internal List<IGraphicItem> GetGraphicItems(DSASM.StackValue svData, RuntimeCore
return null;
}

//Store marshaller for repeated calls to GetCLRObject. Used for short-circuit of re-allocation of marshaller / interpreter object.
private static Interpreter interpreter;
private static ProtoFFI.FFIObjectMarshaler marshaler;

internal object GetCLRObject(StackValue svData, RuntimeCore runtimeCore)
{
if (marshaler != null)
{
return marshaler.UnMarshal(svData, null, interpreter, typeof(object));
}

if (null == runtimeCore.DSExecutable.classTable)
return null;

Expand All @@ -156,16 +165,23 @@ internal object GetCLRObject(StackValue svData, RuntimeCore runtimeCore)

try
{
ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(runtimeCore, false);
interpreter = new ProtoCore.DSASM.Interpreter(runtimeCore, false);
var helper = ProtoFFI.DLLFFIHandler.GetModuleHelper(ProtoFFI.FFILanguage.CSharp);
var marshaler = helper.GetMarshaler(runtimeCore);
marshaler = helper.GetMarshaler(runtimeCore);
return marshaler.UnMarshal(svData, null, interpreter, typeof(object));
}
catch (System.Exception)
{
marshaler = null;
return null;
}
}

internal static void ClearMarshaller()
{
interpreter = null;
marshaler = null;
}
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Engine/ProtoCore/RuntimeCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ProtoCore.DSASM;
using ProtoCore.Lang;
using ProtoCore.Lang.Replication;
using ProtoCore.Mirror;
using ProtoCore.Runtime;
using ProtoCore.Utils;
using ProtoFFI;
Expand Down Expand Up @@ -271,6 +272,7 @@ public void Cleanup()
{
OnDispose();
CLRModuleType.ClearTypes();
GraphicDataProvider.ClearMarshaller();
}

public void NotifyExecutionEvent(ExecutionStateEventArgs.State state)
Expand Down

0 comments on commit 473582b

Please sign in to comment.