Skip to content
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

Use GeneratedDllImport in System.Diagnostics.FileVersionInfo and System.Runtime.InteropServices.RuntimeInformation #52739

Conversation

elinor-fung
Copy link
Member

@elinor-fung elinor-fung commented May 14, 2021

System.Diagnostics.FileVersionInfo:

Original size (B) Converted size (B) + (B) + (%)
linux 16896 18432 1536 9.09
windows 14336 15872 1536 10.71
linux R2R 30208 34304 4096 13.56
windows R2R 22016 26624 4608 20.93

System.Runtime.InteropServices.RuntimeInformation:

Original size (B) Converted size (B) + (B) + (%)
linux 11776 12800 1024 8.70
windows 12288 12288 0 0.00
linux R2R 18432 20992 2560 13.89
windows R2R 18944 19456 512 2.70

cc @AaronRobinsonMSFT @jkoritzinsky

@elinor-fung elinor-fung force-pushed the convert-FileVersionInfo-RuntimeInformation branch from 834dbb1 to 1ade806 Compare May 14, 2021 03:17

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Stat", SetLastError = true)]
internal static extern int Stat(string path, out FileStatus output);
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Stat", CharSet = CharSet.Ansi, SetLastError = true)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is CharSet = CharSet.Ansi needed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had the p/invoke source generators avoid making any assumptions about CharSet if it isn't set, so it requires explicitly specifying either CharSet or MarshalAs when marshalling string/char.

@elinor-fung elinor-fung force-pushed the convert-FileVersionInfo-RuntimeInformation branch from 1ade806 to 00b9f84 Compare May 19, 2021 18:06
@@ -8,6 +8,6 @@ internal static partial class Interop
internal static partial class Kernel32
{
[DllImport(Libraries.Kernel32)]
internal static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo);
internal static unsafe extern void GetSystemInfo(SYSTEM_INFO* lpSystemInfo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is unsafe change necessary? (it is still using the old DllImport)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter was switched to be a pointer - SYSTEM_INFO*

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but since title is "Use GeneratedDllImport..". this change and changes due to this change looked unrelated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general goal of GeneratedDllImport (and this feature branch) is to remove p/invoke overhead - whether that is through using the DllImport source generator to generate the code or using it to find places where we could easily make the p/invoke inlinable.

@elinor-fung elinor-fung merged commit 5513d61 into dotnet:feature/use-dllimport-generator May 20, 2021
@elinor-fung elinor-fung deleted the convert-FileVersionInfo-RuntimeInformation branch May 20, 2021 23:28
@ghost ghost locked as resolved and limited conversation to collaborators Jun 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants