Skip to content

MessagePackSerializer.NonGeneric uses reflection directly on Unity IL2CPP#1087

Merged
neuecc merged 4 commits intomasterfrom
improve-nongenerics-il2cpp
Oct 27, 2020
Merged

MessagePackSerializer.NonGeneric uses reflection directly on Unity IL2CPP#1087
neuecc merged 4 commits intomasterfrom
improve-nongenerics-il2cpp

Conversation

@neuecc
Copy link
Copy Markdown
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.

2 participants