The Wayback Machine - https://web.archive.org/web/20240912225836/https://github.com/dotnet/runtime/pull/97108
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

Reduce defensive copying in PublicKey #97108

Merged
merged 1 commit into from
Jan 20, 2024
Merged

Conversation

vcsjones
Copy link
Member

The bypasses a few more defensive copies in PublicKey.

AsnEncodedData(AsnEncodedData) makes a defensive copy of the data for itself, which the constructor of PublicKey uses. However, there are a few factory methods in PublicKey that create an AsnEncodedData solely for the purpose of transferring to PublicKey. In that circumstance, we can bypass the copy since the creation of the AsnEncodedData already made the defensive copy.

Likewise for X509Certificate2.PublicKey. This shaves several hundred bytes in allocation, scaling with the key size.

@ghost
Copy link

ghost commented Jan 17, 2024

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

Issue Details

The bypasses a few more defensive copies in PublicKey.

AsnEncodedData(AsnEncodedData) makes a defensive copy of the data for itself, which the constructor of PublicKey uses. However, there are a few factory methods in PublicKey that create an AsnEncodedData solely for the purpose of transferring to PublicKey. In that circumstance, we can bypass the copy since the creation of the AsnEncodedData already made the defensive copy.

Likewise for X509Certificate2.PublicKey. This shaves several hundred bytes in allocation, scaling with the key size.

Author: vcsjones
Assignees: vcsjones
Labels:

area-System.Security

Milestone: -

@stephentoub stephentoub merged commit 23eaf25 into dotnet:main Jan 20, 2024
108 of 111 checks passed
tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
@vcsjones vcsjones added this to the 9.0.0 milestone Jan 24, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 24, 2024
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.

4 participants