-
-
Notifications
You must be signed in to change notification settings - Fork 781
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
perf: SyncVar hook invocations no longer instantiate a new action delegate on every call #3615
perf: SyncVar hook invocations no longer instantiate a new action delegate on every call #3615
Conversation
Merge MirrorNetworking/Mirror into cshunsinger/Mirror
interesting, we'll take a look soon after high priority stuff |
This is the commit that caused this performance regression: 5369b8f the new action adds up fast, In a few projects I've seen it causes 100kb+ of allocations per frame... |
Merged this in, no more GC. Thanks! Hopefully I didn't break anything. |
we are still discussing this. |
@cshunsinger merged! |
Let me know if you have any other weaving needs. I love navigating the low-level stuff whether its IL/bytecode, or other funky stuff. With Unity deprecating weaving, that may get tricky. I wonder if the older versions of Unity all support Roslyn because if not then this project will end up being forced to support both Roslyn and IL weaving depending on which version of Unity is used O.O |
Unity is deprecating the IL weaving is done to the dll using mono.cecil. Currently unity has |
This commit makes a couple of small modification to the weaving around syncvars.
I identified 2 cases in which we weave code to invoke the hook for setting a syncvar's value:
As stated in the linked issue, when the syncvar hook is invoked (if there even is a syncvar hook), an instantiation occurs:
new Action<T, T>(HookMethod)
The modifications to the weaving do the following:
Action<T, T>
instance field is added to the class being weaved, whereT
is the field type of the syncvar field.Action<T, T>
instance fields are instantiated tonew Action<T, T>(HookMethod)
for each of the syncvar's hooksnew Action<T, T>(HookMethod)
to the stack, pushthis.hookActionDelegate
to the stack.ILSpy showing the weaving results: generated delegate fields, no more instantiations, and setting up the delegates in the constructor
resolves #3594