opentk/opentk — pull request #14 by thefiddler (2013-12-06 00:17:06+00:00)
Title: New binding implementation based on calli

Avoiding the use of delegates in the bindings has been a long-standing goal for OpenTK.

This branch provides a complete implementation of the OpenGL bindings via calli instructions. This is achieved by post-processing OpenTK.dll with Cecil.

Advantages:
- Reduces OpenTK.dll size from (3.7 MB instead of 5.7 MB)
- Reduces memory consumption (673496 bytes in 10750 objects instead of 2869392 bytes in 72620 objects (!))
- Improves startup time (110 ms instead of 600 ms on Windows x64. Windows x86 reduces this to 30 ms!)
- Removes reflection from the startup path. OpenTK can now be reduced through monolinker! (See [Dependencies/Readme.txt](https://github.com/opentk/opentk/blob/no-reflect/Dependencies/Readme.txt) for usage instructions.)
- Improves interop performance for generic wrappers (i.e. OpenGL functions with void* parameters.)

Disadvantages:
- Calling convention mismatch. Callsites for calli instructions do not support the platformapi calling convention (aka winapi in DllImport), which means that we have to pick either between stdcall (Windows) or cdecl (the rest of the world.) Calling a cdecl function as stdcall is safer than vice versa, so we went for the former. This works ok on x86, but the mismatch is there and may cause unforeseen consequences (in which case we'll need to provide thunks ala libffi - not pretty.)
- Mono fails to marshal string parameters to unmanaged calli callsites. OpenTK now uses manual marshaling for all parameters, including string, string[] and StringBuilder which were previously handled by the runtime. The performance impact (if any) has not been evaluated.

This PR is a work-in-progress and should not be merged yet. More specifically, we are missing a parameter to instruct Generator.Rewrite to use static DllImports instead of calli instructions. This will prove useful for smartphone targets.