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

Move object marshalers to be value type based #1115

Merged
merged 5 commits into from
Feb 26, 2022

Conversation

manodasanW
Copy link
Member

@manodasanW manodasanW commented Feb 25, 2022

Today, when marshaling a reference type, we allocate an IObjectReference to hold onto the ptr which is a heap allocation and needs to also be garbage collected later. This moves to instead using a value type to hold onto it as we use the ptr and dispose of it immediately in marshaling scenarios and don't need to change threads / contexts.

  • Achieved by adding a new CreateMarshaler2 function which returns an ObjectReferenceValue
  • Made further use of it in FromManaged and CopyManaged scenarios where the IObjectReference we allocated was even more temporary as they are used to return a ptr to the ABI.
  • This change doesn't change generic marshalers which I will look at if it is possible to address in a future PR.
Slower diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.QueryInterfacePerf.QueryNonDefaultInterfaceSetProperty 1.26 9.46 11.91
Benchmarks.QueryInterfacePerf.QuerySDKDefaultInterface 1.13 32.67 37.08
Benchmarks.QueryInterfacePerf.QueryFastAbiDerivedDefaultInterface 1.08 11.99 12.98
Faster base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.ReflectionPerf.SetNullableIntDelegate 1.79 980.04 549.00
Benchmarks.ReflectionPerf.SetNullableNonBittableStruct 1.49 2640.33 1773.59
Benchmarks.QueryInterfacePerf.QueryInterfaceOnManagedObject 1.46 348.97 239.73
Benchmarks.ReflectionPerf.SetNullableBittableStruct 1.43 2243.38 1572.90
Benchmarks.QueryInterfacePerf.QueryNativeInterfaceOnComposedObject 1.33 530.61 398.11
Benchmarks.EventPerf.InvokeNativeIntEvent 1.18 860.37 726.61
Benchmarks.ReflectionPerf.IntEventSource 1.16 20921.35 18074.39
Benchmarks.ReflectionPerf.SetUri 1.14 850.08 748.12
Benchmarks.EventPerf.NativeIntEventOverhead 1.10 3732.42 3377.95
Benchmarks.EventPerf.AddAndInvokeNativeIntEventOnNewEventSource 1.10 9210.24 8362.42
Benchmarks.QueryInterfacePerf.DefaultObjectParameters 1.08 1885.35 1744.03
Benchmarks.ReflectionPerf.SetNullableDelegate 1.07 1510.05 1405.92
Benchmarks.EventPerf.AddNativeIntEventToNewEventSource 1.07 7692.39 7186.65
Benchmarks.ReflectionPerf.SetNullableInt 1.07 1699.05 1592.17
Benchmarks.ReflectionPerf.GetNullableTimeSpan 1.06 2267.30 2137.38

@manodasanW manodasanW merged commit 205d2e4 into master Feb 26, 2022
@manodasanW manodasanW deleted the manodasanw/marshalbyvalue2 branch February 26, 2022 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants