-
Notifications
You must be signed in to change notification settings - Fork 171
Fix perf regression in testing for RPC marshalable objects #1330
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
Merged
+28
−14
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -55,7 +55,8 @@ internal abstract partial class MessageFormatterRpcMarshaledContextTracker | |||||
| private static readonly ConcurrentDictionary<Type, (JsonRpcProxyOptions? ProxyOptions, JsonRpcTargetOptions TargetOptions, RpcMarshalableAttribute Attribute)> MarshaledTypes = new(); | ||||||
| private static readonly JsonRpcTargetOptions RpcMarshalableInterfaceDefaultTargetOptions = new() { NotifyClientOfEvents = false, DisposeOnDisconnect = true }; | ||||||
| private static readonly MethodInfo ReleaseMarshaledObjectMethodInfo = typeof(MessageFormatterRpcMarshaledContextTracker).GetMethod(nameof(ReleaseMarshaledObject), BindingFlags.NonPublic | BindingFlags.Instance)!; | ||||||
| private static readonly ConcurrentDictionary<Type, RpcMarshalableOptionalInterfaceAttribute[]> MarshalableOptionalInterfaces = new ConcurrentDictionary<Type, RpcMarshalableOptionalInterfaceAttribute[]>(); | ||||||
| private static readonly ConcurrentDictionary<Type, RpcMarshalableOptionalInterfaceAttribute[]> MarshalableOptionalInterfaces = new(); | ||||||
| private static readonly ConcurrentDictionary<Type, RpcMarshalableAttribute?> RpcMarshalableAttributeCache = new(); | ||||||
|
|
||||||
| private readonly Dictionary<long, (RpcMarshaledContext Context, IDisposable Revert)> marshaledObjects = new Dictionary<long, (RpcMarshaledContext Context, IDisposable Revert)>(); | ||||||
| private readonly JsonRpc jsonRpc; | ||||||
|
|
@@ -103,12 +104,13 @@ internal static bool TryGetMarshalOptionsForType( | |||||
| [NotNullWhen(true)] out JsonRpcTargetOptions? targetOptions, | ||||||
| [NotNullWhen(true)] out RpcMarshalableAttribute? rpcMarshalableAttribute) | ||||||
| { | ||||||
| if (TryGetMarshalOptionsForTypeHelper(typeShape.Type, defaultProxyOptions, out proxyOptions, out targetOptions, out rpcMarshalableAttribute)) | ||||||
| bool? helperResult = TryGetMarshalOptionsForTypeHelper(typeShape.Type, defaultProxyOptions, out proxyOptions, out targetOptions, out rpcMarshalableAttribute); | ||||||
| if (helperResult is not null) | ||||||
| { | ||||||
| return true; | ||||||
| return helperResult.Value; | ||||||
| } | ||||||
|
|
||||||
| if (typeShape.Type.GetCustomAttribute<RpcMarshalableAttribute>() is RpcMarshalableAttribute marshalableAttribute) | ||||||
| if (TryGetRpcMarshalableAttribute(typeShape.Type, out RpcMarshalableAttribute? marshalableAttribute)) | ||||||
| { | ||||||
| // Validation requires more trim annotations than our NativeAOT callers can provide. | ||||||
| // And besides, analyzers should have called out any issues at compile-time. | ||||||
|
|
@@ -133,19 +135,23 @@ internal static bool TryGetMarshalOptionsForType( | |||||
| [NotNullWhen(true)] out JsonRpcTargetOptions? targetOptions, | ||||||
| [NotNullWhen(true)] out RpcMarshalableAttribute? rpcMarshalableAttribute) | ||||||
| { | ||||||
| if (TryGetMarshalOptionsForTypeHelper(type, defaultProxyOptions, out proxyOptions, out targetOptions, out rpcMarshalableAttribute)) | ||||||
| bool? helperResult = TryGetMarshalOptionsForTypeHelper(type, defaultProxyOptions, out proxyOptions, out targetOptions, out rpcMarshalableAttribute); | ||||||
| if (helperResult is not null) | ||||||
| { | ||||||
| // Because events are not checked by the Nerdbank.MessagePack formatter, | ||||||
| // Remove this check when issues related to https://github.com/eiriktsarpalis/PolyType/issues/226 are resolved in this file. | ||||||
| if (type.GetEvents().Length > 0) | ||||||
| if (helperResult is true) | ||||||
| { | ||||||
| throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.MarshalableInterfaceHasEvents, type.FullName)); | ||||||
| // Because events are not checked by the Nerdbank.MessagePack formatter, | ||||||
| // Remove this check when issues related to https://github.com/eiriktsarpalis/PolyType/issues/226 are resolved in this file. | ||||||
| if (type.GetEvents().Length > 0) | ||||||
| { | ||||||
| throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.MarshalableInterfaceHasEvents, type.FullName)); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return true; | ||||||
| return helperResult.Value; | ||||||
| } | ||||||
|
|
||||||
| if (type.GetCustomAttribute<RpcMarshalableAttribute>() is RpcMarshalableAttribute marshalableAttribute) | ||||||
| if (TryGetRpcMarshalableAttribute(type, out RpcMarshalableAttribute? marshalableAttribute)) | ||||||
| { | ||||||
| // Validation requires more trim annotations than our NativeAOT callers can provide. | ||||||
| // And besides, analyzers should have called out any issues at compile-time. | ||||||
|
|
@@ -195,7 +201,7 @@ internal static RpcMarshalableOptionalInterfaceAttribute[] GetMarshalableOptiona | |||||
|
|
||||||
| foreach (RpcMarshalableOptionalInterfaceAttribute attribute in attributes) | ||||||
| { | ||||||
| if (attribute.OptionalInterface.GetCustomAttribute<RpcMarshalableAttribute>() is null) | ||||||
| if (!TryGetRpcMarshalableAttribute(attribute.OptionalInterface, out _)) | ||||||
| { | ||||||
| throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.RpcMarshalableOptionalInterfaceMustBeMarshalable, attribute.OptionalInterface.FullName)); | ||||||
| } | ||||||
|
|
@@ -423,7 +429,7 @@ internal MarshalToken GetToken( | |||||
|
|
||||||
| protected abstract RpcTargetMetadata GetRpcTargetMetadata([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type interfaceType); | ||||||
|
|
||||||
| private static bool TryGetMarshalOptionsForTypeHelper( | ||||||
| private static bool? TryGetMarshalOptionsForTypeHelper( | ||||||
| Type type, | ||||||
| JsonRpcProxyOptions defaultProxyOptions, | ||||||
| [NotNullWhen(true)] out JsonRpcProxyOptions? proxyOptions, | ||||||
|
|
@@ -435,6 +441,7 @@ private static bool TryGetMarshalOptionsForTypeHelper( | |||||
| rpcMarshalableAttribute = null; | ||||||
| if (type.IsInterface is false) | ||||||
| { | ||||||
| // Definitely not. | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -461,7 +468,8 @@ private static bool TryGetMarshalOptionsForTypeHelper( | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| return false; | ||||||
| // Unknown. Caller may want to do more work. | ||||||
|
||||||
| // Unknown. Caller may want to do more work. | |
| // Return null to indicate the interface type requires further validation by the caller. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.