by SparksAndQuarks · 6y ago · 0 comments
I'm playing around with GLFW via PInvoke, which meant marshalling openGL function pointers into managed delegates. In net5.0 preview, I can simply cast IntPtr into a function pointer, and boy, a call to your average openGL method is literally an order of magnitude faster.
Similar optimizations might have been technically possible before, but it required some icky bytecode tinkering.
Interesting, never heard of that. Do you have a source?
I haven’t noticed much overhead when I measured, take a look: https://github.com/Const-me/ComLightInterop#how-it-works That library compiles and runs with .NET Core 2.1.
Update: also there https://docs.microsoft.com/en-us/cpp/dotnet/calling-native-f... they wrote “PInvoke has an overhead of between 10 and 30 x86 instructions per call”
It roughly corresponds to my observation, and I find it fast enough for all practical applications, including GLES rendering on ARM Linux: https://github.com/Const-me/Vrmac/
I have been playing around with interop against LibJpegTurbo Encode() and I am now curious if I've been leaving a ton of performance on the table.