-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
Hack DynamicMethod #351
Comments
I've actually done some experiments with this before. By re-using DynamicMethod and IlGenerators I could reduce (on mono) allocations per delegate creation by 12. Performance wasn't directly impacted that much but since there's a lot of contention for the memory allocator (at least on the version of Mono inside Unity3d) I got some pretty big throughput increases while multi-threading compilation of many delegates. |
@weichx Wow, how did you do that, can you share? At the moment, the most promising part for me is to reuse byte codes internal void EnsureCapacity(int size)
{
if (m_length + size >= m_ILStream.Length)
IncreaseCapacity(size);
}
private void IncreaseCapacity(int size)
{
byte[] temp = new byte[Math.Max(m_ILStream.Length * 2, m_length + size)]; // todo: @perf how to reuse existing ILStream here
Array.Copy(m_ILStream, temp, m_ILStream.Length);
m_ILStream = temp;
} |
That was just a little prototype so I unfortunately don't have the code anymore but the gist of it was directly calling the internal C# runtime methods via reflection (or compiled expression tree). This let me skip all the api overhead that the .NET library introduces.
All of the C# -> C runtime methods have
|
@weichx Thanks for sharing.. will see what can I steal from it :) |
@weichx May be you tried it?... I was thinking, what is the fastest route from the |
probably just getting the |
If you'd like to use private/internal methods without reflection, this maybe usefull: https://github.com/aelij/IgnoresAccessChecksToGenerator |
Use #375 in .NET 8 |
Nope for the #375 until UnsafeAccessorTypeAttribute is supported (likely in .NET 9) |
The text was updated successfully, but these errors were encountered: