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

Remove char[] allocations from RegistryKey and List copy to Array #78558

Closed
wants to merge 0 commits into from

Conversation

Poppyto
Copy link
Contributor

@Poppyto Poppyto commented Nov 18, 2022

Replace char[] allocation with stackalloc memory (no need to rent for 256 chars)
Replace List by string[] to avoid List.ToArray() copy (it must handle rare cases where there are more or less elements during the loop).
Avoid redondant verification EnsureNotDisposed() already called by SubKeyCount & ValueCount.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Nov 18, 2022
@ghost
Copy link

ghost commented Nov 18, 2022

Tagging subscribers to this area: @dotnet/area-microsoft-win32
See info in area-owners.md if you want to be subscribed.

Issue Details

Replace char[] allocation with stackalloc memory (no need to rent for 256 chars)
Replace List by string[] to avoid List.ToArray() copy (it must handle rare cases where there are more or less elements during the loop).
Avoid redondant verification EnsureNotDisposed() already called by SubKeyCount & ValueCount.

Author: Poppyto
Assignees: -
Labels:

area-Microsoft.Win32

Milestone: -

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks. Can you share a perf test with numbers?

@Poppyto
Copy link
Contributor Author

Poppyto commented Nov 21, 2022

Here are the statistics based on enumerate HKCR/CLSID (11128 entries on my computer), there's a 6,3% gain on allocation.

BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19044.2130/21H2/November2021Update)
Intel Core i7-4790K CPU 4.00GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET SDK=7.0.100
[Host] : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2

Method Mean Error StdDev Gen0 Gen1 Allocated
GetKeysNormal 49.66 ms 0.380 ms 0.356 ms 181.8182 90.9091 1.27 MB
GetKeysSpan 48.47 ms 0.370 ms 0.309 ms 181.8182 90.9091 1.19 MB

// * Hints *
Outliers
RegistryBenchmark.GetKeysNormal: Default -> 3 outliers were removed (39.76 ms..40.11 ms)
RegistryBenchmark.GetKeysSpan : Default -> 2 outliers were removed (39.65 ms, 40.18 ms)

@teo-tsirpanis
Copy link
Contributor

Partially overlaps with #77996.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks.

@Poppyto Poppyto closed this Nov 22, 2022
@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Microsoft.Win32 community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants