Skip to content

Conversation

vcsjones
Copy link
Member

@vcsjones vcsjones commented Oct 3, 2025

This implements the suggestion from @jkotas to use sizeof instead of Marshal.SizeOf for blittable structs, or to stop using the native heap entirely for some others.

#120342 (comment)

This does not do the one in StorePal.Windows.Export.cs‎ since I assumed that one will be taken in the linked PR.

@vcsjones vcsjones requested a review from bartonjs October 3, 2025 01:10
@Copilot Copilot AI review requested due to automatic review settings October 3, 2025 01:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Replaces Marshal.SizeOf() calls with the sizeof operator for blittable structs and removes unnecessary native heap allocations in favor of stack usage to reduce overhead and improve performance.

  • Converted Marshal.SizeOf usages to sizeof where applicable.
  • Simplified unsafe interop structures by using stack locals instead of AllocHGlobal + StructureToPtr.
  • Narrowed marshalling overhead in ECCng named curve import path.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
ChainPal.Windows.BuildChain.cs Replaces Marshal.SizeOf with sizeof and introduces an unsafe block for struct size retrieval.
PqcBlobHelpers.cs Marks method unsafe and uses sizeof instead of Marshal.SizeOf; removes redundant inner unsafe block.
MLKem.Windows.cs Replaces Marshal.SizeOf with sizeof for key blob header sizing.
ECCng.ImportExport.NamedCurve.cs Eliminates unmanaged allocations and marshaling by using stack-allocated structs and passing their addresses directly.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

@vcsjones vcsjones merged commit 170fd3d into dotnet:main Oct 3, 2025
85 of 88 checks passed
@vcsjones vcsjones deleted the replace-sizeof branch October 3, 2025 16:38
@vcsjones vcsjones added this to the 11.0.0 milestone Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants