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

MessagePackSerializer.NonGeneric uses reflection directly on Unity IL2CPP #1087

Merged
merged 4 commits into from
Oct 27, 2020

Conversation

neuecc
Copy link
Member

@neuecc neuecc commented Oct 23, 2020

Currently MessagePackSerializer.NonGeneric uses ExpressionTree.Compile to use Generics Serialize/Deserialize.
Compile does not work on AOT environment so uses Compile(preferInterpretation:true) on Unity IL2CPP(ENABLE_IL2CPP).

This PR changes Compile(preferInterpreation:true) to use reflection directly(MethodInfo.Invoke).

  1. Expression interpreter is slow, uses many allocation and finally uses MethodInfo.Invoke, therefore, it is better to use direct reflection in this scenario
  2. Moreover, it doesn't seem to work with IL2CPP, this is a promblem in the LightLambda (ExpressionTree Interpreter) implementation.

Fix for #869 (comment)
and fix for blocking scenario of SignalR Unity support dotnet/aspnetcore#12102 (comment)

I've checked Windows IL2CPP build run succsessfully.
image

Limitation

ref struct can not use reflection(it will solve at .NET 6? dotnet/runtime#10057 ) so ref MessagePackWriter and ref MessagePackReader overload throws NotSupportedException.
Note that this is not supported by ExpressionTree Interpreter either, so an exception will be throwed.

@neuecc neuecc merged commit 896ed3c into master Oct 27, 2020
@neuecc neuecc deleted the improve-nongenerics-il2cpp branch October 27, 2020 06:37
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.

None yet

2 participants