Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-4229 GraphicDataProvider optimization for repeated calls to get similar object types for tessellation #11920

Merged
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;
Comment on lines +145 to +146
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do these need to be static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are static because you only need one Interpreter and FFIObjectMarshaller for the GraphicDataProvider class until the runtime is reset. If you made the instances you would allocate permanently an interpreter and marshaller for every mirror data object and that would be worse than temporary allocation

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that the graphicdataprovider member for mirrordata is static too so it looks like there will only be one instance of graphicdataprovider ever but I guess it doesn't hurt to make these static here as well.


internal object GetCLRObject(StackValue svData, RuntimeCore runtimeCore)
{
if (marshaler != null)
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
{
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