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

Replace Marshal.SizeOf(...) calls for primitive types with sizeof(...) #9220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link

@h3xds1nz h3xds1nz commented Jun 6, 2024

Description

Replaces Marshal.SizeOf calls for primitive types with sizeof operator, saving some unnecessary overhead as the codegen results in a constant number.

I've also replaced the calls for Marshal.SizeOf(typeof(Guid)) with Unsafe.SizeOf<Guid>() as the source counts on 16 bytes in all instances I could find anyways.

Finally, I've replaced some instances of weird ways to retrieve IntPtr size, using its property instead, which also results in a constant in runtime.

Customer Impact

Improved performance, less overhead. Native class static constructor goes from 120ns to 0.02ns for example.

Regression

No.

Testing

Verifying basic library functionality. Changes are minimal.

Risk

No.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested a review from a team as a code owner June 6, 2024 16:03
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant