Skip to content

Conversation

@Sergio0694
Copy link
Owner

Description

The ComputeSharp.D2D1 infrastructure is currently relying on Marshal.GetFunctionPointerForDelegate to marshal a wrapper object for a given T in a non-generic way, such that the internal ID2D1EffectImpl object can call the methods on it. This works, but it's not efficient, and also means you cannot use ComputeSharp in heavily constrained/sandboxed environments, where Marshal.GetFunctionPointerForDelegate is not allowed (as it requires the runtime to allocate a thunk of executable memory at runtime). This PR addresses both problems having the generator emit a non-generic native factory instead.

@Sergio0694 Sergio0694 added enhancement ✨ An improvement to existing APIs optimization 🚀 Performance improvement to existing APIs breaking change 💣 A change that is either binary or source breaking labels Apr 11, 2025
@Sergio0694 Sergio0694 force-pushed the dev/remove-delegate-marshalling branch 2 times, most recently from 699d64e to 06983ab Compare April 11, 2025 07:20
@Sergio0694
Copy link
Owner Author

Saves ~17 KB in a minimal native library, and drops all the delegate marshalling logic:

image

@Sergio0694 Sergio0694 force-pushed the dev/remove-delegate-marshalling branch from 06983ab to f909936 Compare April 12, 2025 20:47
@Sergio0694 Sergio0694 force-pushed the dev/remove-delegate-marshalling branch from f909936 to bf354d5 Compare April 12, 2025 20:48
@Sergio0694 Sergio0694 merged commit 1141f48 into main Apr 13, 2025
24 checks passed
@Sergio0694 Sergio0694 deleted the dev/remove-delegate-marshalling branch April 13, 2025 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change 💣 A change that is either binary or source breaking enhancement ✨ An improvement to existing APIs optimization 🚀 Performance improvement to existing APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants