Skip to content

Conversation

@Sergio0694
Copy link
Member

This PR makes the exported DllGetActivationFactory zero-alloc, skipping the useless string runtimeClassId parameter.
It does so by introducing the following new API to MarshalString:

public static ReadOnlySpan<char> FromAbiUnsafe(IntPtr value);

This allows marshalling an HSTRING to a ReadOnlySpan<char> value, without allocating a temporary string. The "Unsafe" suffix matches the naming convention in the BCL for methods that are not safe when misused. In this case, callers have to make sure not to escape the returned ReadOnlySpan<char> value outside of the scope where the HSTRING is valid.

Then, it updates the generated Module type so that when not on .NET Standard, the GetActivationFactory method will actually take a ReadOnlySpan<char> parameter (with a second string overload just forwarding to it). The new native exports for NativeAOT can then just call this new ReadOnlySpan<char> overload using the new FromAbiUnsafe marshalling method.

@Sergio0694 Sergio0694 added performance Related to performance work authoring Related to authoring feature work AOT labels Nov 29, 2023
@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/marshal-string-span branch from 5cb14c8 to 7a1bba0 Compare November 29, 2023 13:29
@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/marshal-string-span branch 2 times, most recently from 10e492c to a6be48e Compare November 29, 2023 14:25
@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/marshal-string-span branch from a6be48e to c50ccf2 Compare November 29, 2023 16:31
@Sergio0694
Copy link
Member Author

Abandoning this for now because we're currently not building the projections for .NET 7+.
This change would need that, as switching on spans is only supported with C# 11+.

的9GIF (2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AOT authoring Related to authoring feature work performance Related to performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants